How to handle multiple particle systems - from a prefab

Hello,

I am currently undertaking the RPG Course Lesson - Destroy The Unwanted.

I am using a different particle effect/prefab for hit effects than the one used in the lecture and I am unsure how to tackle my current problem.

I have a prefab setup as the master hit effect for projectiles - I was planning to leave the master prefab empty except for theh DestoryAfterEffect script and then create variants that feature different hit effect prefabs within them.

The problem I am facing is that when the DestroyAfterEffect script tries to get Component it fails because there is no ParticleSystem on the master prefab.

Additionally, if I place my custom particle prefabs directly onto the master prefab instead of a variant - I still encounter issues because the prefab(s) I am using for Particle Hit Effects have multiple particle systems attached to an empty game object.

How can I modify the DestroyAfterEffect script to search/scan/find the particle systems stored as child of the prefab gameobject?

Is this a sensible way to approach this?

Is this covered at a later point in the series or do we stick to the basic one particle system prefab?

Any pointers would be appreciated.

1 Like

Hi!

There is a way to find components in child objects.

Another way you could do this is by exposing the particle system variable in the inspector so you don’t have to get the component using code.

It’s not something covered, but it’s fairly simple to gather the child particle systems:

bool AreParticleSystemsActive()
{
    foreach(ParticleSystem system in GetComponentsInChildren<ParticleSystem>())
    {
         if(system.IsAlive()) return true;
    }
    return false;
}

Hello again,

@ Yee - thanks for the speedy reply and nudge in the right direction.

@ Brian_Trotter - thank you for the code snippet.

Looking at the solution it seems super straightforward in hindsight. Doh!

Thank you both for your help, very much appreciated.

Cheers!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms