Further collision beyond the OnCollisionEnter() event

I am creating a game where I need collision between blocks of the same colour to be acted upon. The blocks are children of gameobjects which act to create clusters of blocks - kind of like Tetris shapes. The rigidbody component thus belongs to the parent gameobject and OnCollisionEnter is called only when two parents collide. I have no problem identifying when matching blocks collide when OnCollisionEnter is called. Here is the code I use for that:

void OnCollisionEnter(Collision collision)
    {
        foreach (ContactPoint c in collision.contacts)
        {
            if ((c.thisCollider.renderer.material.color == c.otherCollider.renderer.material.color)
                && (c.thisCollider.renderer.material.color != Color.gray)
                && (c.otherCollider.renderer.material.color != Color.gray))
            {
                ScorePoint = true;
                c.thisCollider.renderer.material.color = Color.gray;
                c.otherCollider.renderer.material.color = Color.gray;
            }
        }

(the blocks are coloured gray after colliding with the same colour)

The actual problem I have is illustrated below. In the first frame the gameobjects collide and no matching colours are detected. The collision between the gameobjects holds until two matching coloured blocks are touching, but of course OnCollisionEnter will not be called. I have tried playing with the OnCollisionStay event but I haven’t managed to do so without raising huge performance issues on mobile devices.

If anyone has any advice it would be greatly appreciated. Perhaps a solution which works only in this special case where all the individual blocks are cubes?

16646-qu_example.png

It seems like all your problems would be solved if each cube had it’s own collider. Then you can just test each cube-cube collision for matching colors in OnCollisionEnter, rather than testing each child of the parent via the material at each collision point (which you are doing via the material of the collision points). You can still nest the cubes under a parent object so they move together, and you can still access the parent from the child cubes if necessary etc.

This should also perform somewhat better when processing the collisions as you don’t have to test each collision point.