[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.
- sphere check for targets to damage
- 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