enemyDeathFX fire on game start issue,

Hi All

I’ve haven’t watched that solution yet but I’m working on the solo challenge. Specifically towers shooting the enemy ship with particles which works ok. I’m trying to use the same same instantiation method we used with the enemies in rail assault but I have 1 annoying issue.

I have a gameobject in the root of the scene called enemyDeathFX. This has a particle explosion and sound affect attached.

When a particle from the tower guns hit the enemy we do a ;
GameObject fx = Instantiate(enemyDeathFx, transform.position, Quaternion.identity);
Destroy(fx, 2.0f);

This allows for mutiple hits as we reduce the hitcounter for this enemy.

The issue I have is as the gameobject is a normal gameobject it ‘goes off’ as soon as I hit play before anything is fired at the enemy ship. This is because the enemyDeathFX is enabled in the inspector. Works ok after the initial explosion :wink:

I can disable it in the inspector but then it never actually does anything.

The rubbish ‘solution’ i’ve found is child enemyDeathFX to the enemy and do a enemyDeathFx.SetActive(true); The first time OnParticleCollision(GameObject other) is called for this enemy. Also disable in inspector.

Doesn’t feel right to me !

Hi Jeff,

Do you currently have the Play on Awake property set to true for the ParticleSystem on the GameObject in question? This would cause the behaviour you are describing.

Hi Rob- THanks for the fast response.
In my enemyDeathFX object I have particle and audio set to playonawake, If I switch these off the gameobject does nothing when it’s Instantiate’d ( I can see the clone object appearing during gameplay )

Don’t I feel like an idiot !
The problem is I have the enemyDeathFX sitting in the scene when the level starts.
The correct solution is to NOT do this !
GameObject fx = Instantiate(enemyDeathFx, transform.position, Quaternion.identity) brings the prefab into the scene as required. ( enabled in inspector and playonawake set to true for both particle and audio )

My problem was caused because I had added it to the scene. That’s a doh! moment.

1 Like

Hi Jeff,

So, without the Play on Awake being set to true you would then need to call Play on the appropriate component based on the conditions in which you want it to play.


Updated Mon Jan 21 2019 19:28

Oh I see, sorry, I assumed you were instantiating via code and wanted to not have the particles and audio active immediately.

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

Privacy & Terms