Skip to content

Commit

Permalink
Catch Exceptions tossed by GameObject.transform after parts have been…
Browse files Browse the repository at this point in the history
… removed by Unity.
  • Loading branch information
toadicus committed Jul 10, 2014
1 parent 3c8e5a6 commit 78f7b81
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions PersistentEmitterManager.cs
Expand Up @@ -66,19 +66,32 @@ public void FixedUpdate()
// If the gameObject is null ( when ? I forgot ... )
// or the tranform parent is null ( Emitter detached from part so the particle are not removed instantly )
// then the emitter won't be updated by the effect FixedUpdate Call. So update it here
if (persistentEmittersCopy[i].go == null
|| persistentEmittersCopy[i].go.transform == null
|| persistentEmittersCopy[i].go.transform.parent == null)
if (persistentEmittersCopy[i].go == null)
{
persistentEmittersCopy[i].EmitterOnUpdate(Vector3.zero);

if (persistentEmittersCopy[i].pe.pe.particles.Count() == 0)
Transform pecTransform = null;

try
{
pecTransform = persistentEmittersCopy[i].go.transform;
}
catch (NullReferenceException)
{
EffectBehaviour.RemoveParticleEmitter(persistentEmittersCopy[i].pe);
persistentEmitters.Remove(persistentEmittersCopy[i]);
if (persistentEmittersCopy[i].go != null)
// Destroy the gameobject so avoid exception handling in the future?
continue;
}

if (persistentEmittersCopy[i].go.transform.parent == null)
{
persistentEmittersCopy[i].EmitterOnUpdate(Vector3.zero);

if (persistentEmittersCopy[i].pe.pe.particles.Count() == 0)
{
Destroy(persistentEmittersCopy[i].go);
EffectBehaviour.RemoveParticleEmitter(persistentEmittersCopy[i].pe);
persistentEmitters.Remove(persistentEmittersCopy[i]);
if (persistentEmittersCopy[i].go != null)
{
Destroy(persistentEmittersCopy[i].go);
}
}
}
}
Expand Down

0 comments on commit 78f7b81

Please sign in to comment.