I have a script with a OnCollisionEnter2D function. It seems to work fine most of the time. But every once in a while, an error occurs: the Collision2D object passed to the function does not have a gameObject member. This is unexpected, according to the Collision2D documentation.
I have structured my code to detect this condition, like so:
void OnCollisionEnter2D( Collision2D coll ) {
if ( coll.gameObject ) {
//...do some stuff...
} else {
print( "Object " + name + " collided with a collider with no game object" );
}
}
Usually, Unity will hit this condition, then crash. I’m at a loss as to how to debug this, seeing as how Unity is crashing. Any ideas as to where to start? Thanks.