# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/sample-tutorial-03-flexible-gameplay-in-fortnite
# Local doc: epic-docs/documentation/en-us/fortnite/sample-tutorial-03-flexible-gameplay-in-fortnite.md
# Section: Spawning and Removing Prefabs
if:
SimulationEntity := GetSimulationEntity[]
then:
loop:
race:
block:
TriggerVolume.AgentEntersEvent.Await()
SimulationEntity.AddEntities(array{ PrefabToSpawn })
PrefabToSpawn.SetGlobalTransform(SpawnTransform)
block:
TriggerVolume.AgentExitsEvent.Await()
PrefabToSpawn.RemoveFromParent()
Verse Library
verse
03 Spawning And Removing Prefabs
Automatically spawns a prefab when an agent enters a trigger and removes it when they leave.
extracted-snippets/documentation/en-us/fortnite/sample-tutorial-03-flexible-gameplay-in-fortnite/03-spawning-and-removing-prefabs.verse