Spawn
Menu Path : Context > Spawn
The Spawn Context controls how many instances the system feeds into an Initialize Context. This Context handles a set of built-in blocks to control the spawn rate. You can also implement VFXSpawnerCallbacks to create a custom behavior.
This Context spawns particles within spawn loops. You can specify the number of loops it processes, the duration of each loop, and whether or not to have a delay before or after each loop.
Context settings
Setting | Type | Description |
---|---|---|
Loop Duration | Enum | (Inspector) Specifies how long this Context produces particles. The options are: • Infinite: Produces particles continuously. • Constant: Produces particles for a specific duration that you can specify. After this time, if Delay Mode is set to After Loop or Before And After Loop, this Context pauses particle spawning. What it does after this pause depends on the Loop Count and Delay Mode. • Random: Produces particles for a random duration between a minimum and maximum value. After this time, if Delay Mode is set to After Loop or Before And After Loop, this Context pauses particle spawning. What it does after this pause depends on the Loop Count and Delay Mode. |
Loop Count | Enum | (Inspector) Specifies how many times this Context loops for. During each loop, this Context triggers particle spawns. The options are: • Infinite: Loops indefinitely. • Constant: Loops a specific number of times. • Random: Loops a random number of times between a minimum and maximum value. |
Delay Mode | Enum | (Inspector) Specifies where in the loop this Context processes a delay. The options are: • None: Does not process a delay. • Before Loop: Processes a delay before the spawn loop. • After Loop: Processes a delay after the spawn loop. • Before And After Loop: Processes a delay before and after the spawn loop. |
Delay Before Random | Bool | (Inspector) Toggles whether the delay before the spawn loop is a random value between a minimum and a maximum value or a constant value. This setting is only visible if you set Delay Mode to Before Loop or Before And After Loop. |
Delay After Random | Bool | (Inspector) Toggles whether the delay after the spawn loop is a random value between a minimum and a maximum value or a constant value. This setting is only visible if you set Delay Mode to After Loop or Before And After Loop. |
Context properties
Setting | Type | Description |
---|---|---|
Loop Duration | float/Vector2 | The duration of the spawn loop. This property only appears if you set Loop Duration to Constant or Random. |
Loop Count | int/Vector2 | Defines how many loops the Context processes before going back to the initial state. This property only appears if you set Loop Count to Constant or Random. |
Delay Before | float/Vector2 | The duration of the delay before the spawn loop. This property only appears if you enable Delay Before Random. |
Delay After | float/Vector2 | The duration of the delay after the spawn loop. This property only appears if you enable Delay After Random. |
Flow
Port | Description |
---|---|
Start | Connection from an Event, a GPU Event, or another Spawn Context. |
Stop | Connection from an Event, a GPU Event, or another Spawn Context. |
SpawnEvent | Connection to an Initialize Context or another Spawn Context. |
Remarks
System lifecycle
For a visualization of the looping and delay system, see the below illustration.
The lifecycle of the looping phases is split up into states that the Spawn Context handles internally. The lifecycle is as follows:
Step | State description |
---|---|
1. Initial State | The initial state of a spawn Context is VFXSpawnerLoopState.Finished. At this stage, the Context is waiting for Start flow input to trigger. This occurs when you call VisualEffect.Play. |
2. OnPlay | When the Start flow input triggers, if there are [custom spawner callbacks], the Context triggers VFXSpawnerCallbacks.OnPlay. The Spawn Context evaluates the graph to set the loop count. It then proceeds to the next step. |
3. Reset Delay durations | The Spawn Context evaluates the graph and initializes: • The delayBeforeLoop time. • The loopDuration time. • The delayAfterLoop time. It then sets the totalTime to zero and proceeds to the next step. |
4. Awaiting before the loop. | The loopState transitions to DelayingBeforeLoop. During this phase, while totalTime is below delayBeforeLoop, the Context waits. When totalTime exceeds delayBeforeLoop, the Context sets totalTime to zero and proceeds to the next step. |
5. Looping | The loopState transitions to Looping and the Context sets playing to true. During this phase, while totalTime is below loopDuration, the Spawn context evaluates the internal spawn blocks and spawns particles. When totalTime exceeds loopDuration, the Context sets totalTime to zero and proceeds to the next step. |
6. Awaiting after the loop | The loopState transitions to DelayingAfterLoop. During this phase, while totalTime is below delayAfterLoop, the Context waits. When totalTime exceeds delayBeforeLoop, the Context sets totalTime to zero and proceeds to the next step. |
7. Verify final state. | Finally, the Context increments the loopIndex. If the new loopIndex is less than the loopCount, the lifecycle moves back to step 3. Otherwise, it moves back to the initial step, 1, and awaits a new Start flow input trigger. |
Linking Spawn Contexts
The standard way to turn a Spawn Context on and off is to use an input event. When there isn’t an input to a Spawn Context's Start input flow slot, the Visual Effect Graph implicitly connects the “OnPlay” event. Also, when there isn't an input to a Spawn Context's Stop input flow slot, the Visual Effect Graph implicitly connects the “OnStop” event.
Another way to turn a Spawn Context on and off is to link it to another Spawn Context. To do this, link a Spawn Context's, SpawnEvent output flow slot to another Spawn Context's Start input flow slot. In that case, the event attributes state is automatically transferred from the first Spawn Context to the second. You can then connect to the first Spawn Context's Start and Stop input flow slots to turn the connected Contexts on and off.