Multiple collision issue

I’m having a problem where I want to destroy the ball after it collides, and do some stuff. It should only do stuff once in it’s lifetime.
Example:

OnCollisionEnter(Collision collided)
{
Destroy(gameObject);
//Do some stuff once
print("Did stuff");
}

The problem is, that at the exact right moment, the object can collide with two objects at the same time, meaning that stuff is happening twice before it gets destroyed (I’m getting “Did stuff” twice in the console). It’s as if OnCollisionEnter is being called twice in the same frame.

I tried doing some sort of locking mechanism such as:

//CollisionEnter
if (!lock)
{
lock = true;
}
else
{
return;
}
//do stuff
lock = false;

However that did not work as it is probably getting locked in the same update that it’s doing stuff the second time.

Does anyone know a fix for this?

I managed to fix this by only doing stuff in the Update() function once the collision happens. The collision function only sets a boolean collided to true. The update funciton proceeds to destroy the object and do stuff only once.