[Solved] Unable to instantiate an object from within the OnTriggerEnter callback.

[SOLUTION]
The object was instantiating but it was instantly destroying itself due to update order of some scripts.

[ORIGINAL PROBLEM]
Hello again helpful Unity Answers community!

I have encountered something which is either a bug or the way the engine works, either way it might be something that needs looking in to.

I have a proximity bomb, that upon entering of it’s radius it explodes. Now the explosion is comprised of 2 parts.

  1. sphere check for targets to damage
  2. instantiation of visual effects

The proximity bomb can also be exploded when it is shot, which executed Detonate when the message ApplyDamage is sent to it.
Exploding it this way spawns the effect, as it is still technically within the update loop. But as mentioned before, when it is triggered via the trigger collider nothing is spawned.

This is how I was calling it / would like to call it:

void OnTriggerEnter(Collider collider)
{
	if(collider.tag == "Enemy")
	{
		Detonate();
	}
}

void ApplyDamage(DamageInfo info)
{
	Detonate ();
}

Doing it this way half works, in the sense that that the detonation happens, does the damage and removes the bomb object. But with no visual effects from the trigger.

However, doing it this way works perfectly:

void OnTriggerEnter(Collider collider)
{
  	if(collider.tag == "Enemy")
   	{
   		m_doDetonate = true;
   	}
}

void ApplyDamage(DamageInfo info)
{
  	Detonate ();
}

void Update()
{
	if (m_doDetonate) 
		Detonate ();
}

Any ideas on why this is and how to fix it? I really hate using the Update() for one time checks when it should be doable via callback.

Whole script available: Proximity Bomb, Inherited Class

There really isn’t anything like that attached to the object.

I restepped through the script with the desired method and no object is shown in the hierarchy even though it runs the instantiation code, the Vector3 is still intact.

–Edit–
Oh bloody hell, there was a script attached to it which handled it’s destruction (totally forgot about it and it was hidden… sandwiched between audio and particle XD). The script uses particle count to judge whether or not to delete the object. Obviously after the physics step where the emitter hasn’t had chance to emit yet… that count is going to be zero. I added an extra condition to check to see if the emitter is playing as well as having the count at zero. Works fine. I would have thought that the particle emitter would have been processed before this script though, given the component order (which should have averted this problem). Ah well… s’all good now.