Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Instantiate from Pool#

Game Object / Creation / Instantiate from Pool

Description#

Creates or recycles a previous instance of a prefab from a pool

Parameters#

Name Description
Game Object The template game object that makes a copy
Position The position of the new game object
Rotation The orientation of the new game object
Parent An optional parent object of the new instance
Capacity The minimum number of instances that can be stored in the pool
Lifetime Whether the instance has a fixed lifetime duration
Duration The duration in seconds of the instance in seconds

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("Instantiate from Pool")]
    [Image(typeof(IconCubeSolid), ColorTheme.Type.TextLight, typeof(BadgeBolt))]
    
    [Description("Creates or recycles a previous instance of a prefab from a pool")]
    [Category("Game Object/Creation/Instantiate from Pool")]
    
    [Parameter("Game Object", "The template game object that makes a copy")]
    [Parameter("Position", "The position of the new game object")]
    [Parameter("Rotation", "The orientation of the new game object")]
    [Parameter("Parent", "An optional parent object of the new instance")]
    [Parameter("Capacity", "The minimum number of instances that can be stored in the pool")]
    [Parameter("Lifetime", "Whether the instance has a fixed lifetime duration")]
    [Parameter("Duration", "The duration in seconds of the instance in seconds")]
    
    [Keywords("Create", "New", "Recycle", "Pooled")]
    
    [Serializable]
    public class InstructionCoreGameObjectInstantiateFromPool : Instruction
    {
        [SerializeField] private GetGameObject m_GameObject = new GetGameObject(
            new TypeGameObjectPrefab()
        );

        [SerializeField] private GetVector3 m_Position = new GetVector3();
        [SerializeField] private GetQuaternion m_Rotation = new GetQuaternion();

        [SerializeField] private PoolConfig m_PoolConfig = new PoolConfig();

        protected override string GetTitle(GameObject source) => $"Instantiate {this.m_GameObject}";

        protected override Awaitable Run(Args args)
        {
            GameObject gameObject = this.m_GameObject.Get(args);
            if (gameObject == null) return Done;

            PoolManager.Pick(
                gameObject,
                this.m_Position.Get(args),
                this.m_Rotation.Get(args),
                this.m_PoolConfig.GetCapacity(args),
                this.m_PoolConfig.HasDuration
                    ? (float) this.m_PoolConfig.GetDuration(args)
                    : -1f,
                this.m_PoolConfig.TimeMode
            );
            
            return Done;
        }
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.