API ReferenceGE Extensionsflowgraphnodesscene
Spawn Prefab (Flowgraph Node)
- **Node Name:** `Spawn Prefab`
Overview
- Node Name:
Spawn Prefab - Category: (once behavior)
- File:
extensions/flowgraph/nodes/scene/spawnPrefab.lua
Creates and manages a prefab in the scene. Supports .prefab.json and legacy .prefab formats. Spawns once and persists until reset or execution stop.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Standard inflow |
resetVeh | flow (impulse) | Resets vehicles inside this prefab to spawn positions |
path | string | Path to the prefab file |
name | string | (Hidden) Custom prefab object name |
pos | vec3 | Position to spawn the prefab |
useGlobalTranslation | bool | (Hidden) Use global translation (default true) |
silent | bool | (Hidden) Suppress file-not-found errors |
Output Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Standard outflow |
created | flow (impulse) | Fires when prefab is created |
id | number | Scene tree ID of the spawned prefab |
origVehId | number | Player vehicle ID before spawn (spawning prefabs with vehicles switches the active vehicle) |
success | bool | (Hidden) Whether the prefab loaded successfully |
Behavior
work()- Each frame with flow:- Spawns the prefab on first trigger (once behavior).
- On
resetVehimpulse, restores all vehicle positions within the prefab. - Sets
createdimpulse andsuccessoutput on spawn.
createObject()- Resolves the file path (trying.prefaband.prefab.jsonextensions), callsspawnPrefab(), adds to MissionGroup, and registers with the prefab module.
How It Works
- Captures the current player vehicle ID before spawning (since prefab vehicles may steal focus).
- Resolves the prefab path using
mgr:getRelativeAbsolutePath()with fallback extensions. - Calls the engine
spawnPrefab(name, file, pos, rot, scale, useGlobalTranslation). - The spawned object is flagged
canSave = falseand added to MissionGroup. - Registers with
mgr.modules.prefab:addPrefab()for lifecycle tracking. - On cleanup, the objects list is cleared (prefab module handles actual deletion).
Example Usage
-- Spawn a traffic prefab at the origin:
-- path = "levels/west_coast_usa/scenarios/traffic_setup.prefab.json"
-- pos = {0, 0, 0}Key Dependencies
spawnPrefab(name, file, pos, rot, scale, globalTrans)- engine functionself.mgr.modules.prefab:addPrefab()- registers prefab for lifecycle managementself.mgr.modules.prefab:restoreVehiclePositions()- resets vehicles in prefab
Additional Methods
C:_executionStopped()
Called when graph execution stops. Used for cleanup.
C:clearObjects()
Node method.
C:destroy()
Destroys the node and cleans up any created objects.
C:init(mgr, ...)
Initializes the node, setting up pins and default properties.
Parameters:
mgr...
C:onClientEndMission()
Cleanup callback when the mission/level ends.
C:postInit()
Called after initialization is complete for additional setup.
See Also
- Collection Marker (Flowgraph Node) - Related reference
- Custom Lua Command (Flowgraph Node) - Related reference
- Get Object Field (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide