Colliders2D not working under same parent?

During the development I have found strange Collider2D behavior in Unity 4.6.0f1 (not sure if it is a 4.6 issue?).

To reproduce a problem I created a separate project and very simple scene with 3 objects (Picture 1). Each object have only Rigidbody2D and BoxCollider2D. The red one have also simple move script (only add force in each direction on keypress).

When all objects are root in the scene hierarchy everything works fine (Picture 2). The problem occurs when those objects have the same parent:

Parent

  • TestObjectPlayer
  • TestObject
  • TestObject
  • TestObject

Than Colliders 2D stops working (Picture 3). The funny thing is that when I simply during run-time disable the Collider on the Player Object and than enable it again it starts working.

Is it a bug in 4.6 or normal behavior?

This seems to be a bug in Unity 4.6.0f1: http://forum.unity3d.com/threads/unity-4-6-0b21-2d-colliders-broken.277341/

I’m having the same issue. Submit a bug report and hopefully it gets fixed soon.

This is what we’re seeing here as it seems related to some prefab changes however your post seemed to indicate you were seeing it outside of prefabs.

Thanks for the confirmation.

Found temporary solution until the bug is fixed.
In Start() function just disable and enable Collider:

collider2D.enabled = false;
collider2D.enabled = true;

Or if you have multiple Colliders:

Collider2D[] colliders2D = GetComponents<Collider2D>();
foreach (Collider2D collider2D in colliders2D) {
	collider2D.enabled = false;
	collider2D.enabled = true;
}

For me looks like it is working. I needed something to continue development.

A script like this on the same gameobject as each collider will let you at least work in the meantime:

using UnityEngine;
using System.Collections;

public class ColliderBugFix46rc1 : MonoBehaviour {

	void Start () {
		collider2D.enabled = false;
		collider2D.enabled = true;
	}
}