Ignore collision is not working in built game

,

In my game enemies shouldn’t face each other and object “coin”. I wrote code:
void Start()
{
Physics2D.IgnoreCollision(enemy1, enemy2);
Physics2D.IgnoreCollision(enemy1, enemy3);
Physics2D.IgnoreCollision(enemy1, enemy4);
Physics2D.IgnoreCollision(enemy1, enemy5);
Physics2D.IgnoreCollision(enemy1, enemy6);
Physics2D.IgnoreCollision(enemy1, enemy7);
Physics2D.IgnoreCollision(enemy1, enemy8);
Physics2D.IgnoreCollision(enemy1, enemy9);
Physics2D.IgnoreCollision(enemy1, enemy10);
Physics2D.IgnoreCollision(enemy2, enemy3);
Physics2D.IgnoreCollision(enemy2, enemy4); …
etc.
When I open the game in Unity games preview, this code work.
But when I had built the game and tried to play it, something went wrong and enemies collided with each other.
I will be grateful for any help.

4480546--412366--upload_2019-4-29_10-48-4.png

What platform are you running your build on?

I don’t know why it doesn’t work, but in any case using layer-based collision will be easier for this, especially as you add more objects to your scene. It might fix your issue, too.

1 Like

This game was built for Windows. I changed this code a bit earlier and it is working right now, but I still do not understand why my first variant doesn`t work.