I’m wasting entirely too much time on this. It really has me confused.
The following line (below) is throwing a NullReferenceException:
BlowsUpOnParticleCollisions collisionReceiver = particle.collisionCollider != null ? particle.collisionCollider.gameObject.GetComponent() : null;
I wrapped this in a try/catch, and “particle.CollisionCollider” appears to be null. I can’t understand how this is possible, even in a freakish threading scenario. I’ve guarded against nulls before attempting the call and then again inline.
I should note that when GetComponent doesn’t return null this works. Not all of the objects in my scene “blow up on particle collision”. Even though this script throws copious exceptions, the effect I’m going after still works…I just can’t have my script throwing exceptions with wild abandon.
onParticleCollision is an event.
particle.collisionCollider is of type Collider - so it’s a reference type (class).
private void onParticleCollision(PlaygroundEventParticle particle)
{
if(particle != null && particle.collisionCollider != null && particle.collisionCollider.gameObject != null)
{
BlowsUpOnParticleCollisions collisionReceiver = particle.collisionCollider != null ? particle.collisionCollider.gameObject.GetComponent<BlowsUpOnParticleCollisions>() : null;
if (collisionReceiver != null)
{
collisionReceiver.CurrentCollisionCount++;
}
}
}
Where have I gone wrong?
I’ll cry if it’s something super obvious ![]()