Particle tips ParentFields

From PopcornFX
Jump to navigation Jump to search

For PK-Fx Editor version : 1.5.5 and above
Main page: Particle tutorials

With parent fields, you will be able to get particle fields of the "parent" particle over spawner evolver spawner evolvers and CParticleEvent particle events.

Parent fields over spawner evolver spawner evolvers

A Spawner evolver spawner evolver has a single "parent" : the descriptor inside which the spawner evolver Spawner evolver is located. So, PopcornFX will transparently declare every field of the parent descriptor in the Spawner Script of the spawner evolver 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 CParticleEvent particle events

CParticleEvent Events are less straightforward: as a Particle Layer layer can be triggered by multiple CParticleEvent events from different layers that have different particle fields, you will need to specify in the child Particle Layer layer which parent field you will expect as parent field with the Virtual Parent Fields list in Particle fields particle fields.

If one of the CParticleEvent 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 spawner evolver: parent.MyVirtualParentField


Let's create a simple particle emiter with randomized colors and a spawner evolver spawner evolver:

Tips ParentFields EvSpawner Start.png

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:

Tips ParentFields EvSpawner.png

In the layer 'Layer_1', one could add a CParticleEvent particle event 'OnCollide' triggering another Particle Layer layer called 'Collision':

Tips ParentFields Event Start.png

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:

Tips ParentFields Event End.png


  • You can only specify parent fields over a Particle Layer layer (ie: you cannot get parent fields through Layer group layer group)
  • As parent fields "receive" the values at spawn, you can only access those values in the Spawner Script.