I came up to this scenario which I think must be rather common.
I have several similar objects (asteroids) floating in space.
I want to draw some impact and play sound when they collide with each other.
They are instances of the same Prefab, so they have the same tag and the same Monobehaviour.
When they collide, I get two collisions, not just one. One detected by the first, another by the second.
Is there a simple way to just discard the second call ?
You could compare two GameObjects by their instance IDs, then only choose the ID with the lowest value. Personally, I’ve being something similar recently, but assigned IDs in a similar manner to the suggestion by DFLY. However, there is another potential issue. You also need to make sure you are not repeating the same collision… you can have more than one collision per frame between the same two colliders. Unity - Manual: Order of execution for event functions
To avoid this issue, you could set a flag during FixedUpdate to prevent further collisions during that frame. You would then reset the flag during Update.
What you can do is give each instance of the prefab a number one unit higher than the last prefab e.g.: “1 , 2 , 3 …” Then use an if statement to make only the largest numbered prefab detect the collision. To number your prefabs to start with use something like: