BoxCollider2D fails verification, where CircleCollider2D does not

I have a 2D game object with no parent and a 2D box collider set with trigger enables. The dimensions are quite large.

When I place the game object in the scene, manually, it works just fine. However, when I instantiate the prefab, it doesn't work; in the inspector view, under the collider component a notification appears:

The collider did not create any collision shapes as they all failed verification. This could be because they were deemed too small or the vertices were too close. Vertices can also become close under rotations or very small scaling.

When I switch to scene view, while the game is in play mode, I can not see the collider boundaries. Surprisingly, everything works fine, if I use the circle collider. Does anyone know what the problem could be?

4 Answers

Read the error carefully - it took me a day to find out that the answer is in that error.

See if somehow the scale of your game object becomes 0 or any of that side is overlapping with other side. If that happens, the box collider won't work and will give that error message.

You can try this

GameObject canon = Instantiate(prefab);
canon.GetComponent<BoxCollider2d>().size=new Vector2(10f,10f);


Increase your canon box collider size based on box collider visible on your scene window.

• I did what you said however it still doesn't work. In the Inspector the collider size is shown to be 10 by 10 so it doesn't seem to be due to small size. – Vadim Tatarnikov Apr 11 '16 at 12:03

You might try adding the collider after the object is instantiated so the calculations are correct. So first remove the collider from the prefab and then :

//After prefab is created

prefabCloneName.AddComponent<BoxCollider2D>();

• Thanks for replying, but unfortunately the problem still appears when the collider is added. – Vadim Tatarnikov Apr 11 '16 at 12:28

In the above diagram, we can see that size should be relatively appropriate, and there should not be any rotation. This could be a false assumption. What we do not see is the game object hierarchy, in which our problem object could still be parented1 under another game object.

Should the game object be parented to another game object, you still want to observe the scale and rotation of any parents. Both of these will be multiplied by local values, in order to give world values. World values are what really matter, in context of the error being displayed.

In this case, I believe this could point to additional rotation. You say that the circle collider works fine - this would not be the case, if world scale really did make the game object too small.

However, as discussed on the Unity Answers site, the box collider can still throw this error as it approaches 90 degree rotations. This is because the rotation converts to a skew in the interpreted size, and at 90 degrees, one of the axis is going to be approaching rather minimal values. As the error reports, we can't have that.

Ultimately, if this is the case, you need to figure out if you need the parent. If you do, in turn, you should decide if you need rotation. If you need rotation, you should use a circle collider, instead.

Failing all that, due to the precise nature of your problem, I would honestly put this down to a Unity bug.

1 It occurs to me that I have missed the additional note that there is no parent, but it is still worth addressing the code where you instantiate objects. You can set a parent during instantiation without it visually displaying so in the hierarchy. I'm unsure why such a method would be useful, as it took me some time to figure it out, too.