Aego Русский

Spawning and pools

scene.Spawn places a copy of a prefab; scene.Despawn returns it to a pool, and the next Spawn of the same prefab reuses it instead of building a new one.

@export var Bullet AssetRef<Prefab>

func Ready() {
  scene.Pool(Bullet, 32)
}

func Fire() {
  b := scene.Spawn(Bullet, node.WorldPosition())
}
Function
scene.Spawn(prefab, pos) NodeRef under the scene root at a 2D position
scene.SpawnAt(prefab, parent, pos, rot) NodeRef under a parent with a local position and rotation
scene.Despawn(node) back to the pool; a node that did not come from a pool is destroyed
scene.Pool(prefab, n) build n copies now; their Ready runs now