Particle tips ParentFields
For PK-Fx Editor version : 1.5.5 and above
Main page: Particle tutorials
Parent fields over spawner evolvers
A spawner evolver has a single "parent" : the descriptor inside which the Spawner evolver is located. So, PopcornFX will transparently declare every field of the parent descriptor in the Spawner Script of the Spawner evolver under the namespace parent:
// Spawn script: Color = parent.Color; // will set the Color field to the Color of the parent particle that spawns us
Parent fields over particle events
Events are less straightforward: as a layer can be triggered by multiple events from different layers that have different particle fields, you will need to specify in the child layer which parent field you will expect as parent field with the Virtual Parent Fields list in particle fields.
If one of the Events that trigger your Layer doesn't have all the required VirtualParentFields, you will get some explicit error messages.
Once your Virtual Parent Fields are correct, you can get parent fields in the Spawner Script the same ways as with spawner evolver: parent.MyVirtualParentField
Let's create a simple particle emiter with randomized colors and a spawner evolver:
Before parent fields, getting the particle trails to inherit the color of the spawning particle could have been quite tricky, and sometimes impossible.
Now, a simple Color = parent.Color in the trail Spawner Script gets the job done:
In the 'Collision' Layer, to get the Color of the particle that triggered the event, we will need to tell PopcornFX which field has to exist in the parent Layer:
Go to the particle Fields of 'Collision', scroll to Virtual Parent Fields, and add a float4 Color.
If the Color field actually exists in all the Layers that trigger 'Collision', the spawn script will have access to parent.Color:
- You can only specify parent fields over a layer (ie: you cannot get parent fields through layer group)
- As parent fields "receive" the values at spawn, you can only access those values in the Spawner Script.