- Home /
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?
Answer by bpolley · Nov 12, 2014 at 02:52 AM
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.
Yes, I experienced the problem with the prefab instances. Not tested it with the standalone Objects (with no prefab) though.
Answer by MelvMay · Nov 12, 2014 at 12:11 PM
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.
Answer by 0x7C00 · Nov 13, 2014 at 07:02 PM
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.
Answer by IvanAlvarez · Nov 13, 2014 at 07:00 PM
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;
}
}
Use a script like this in the gameobjects that have 2d colliders to have they work while a patch is released:
using UnityEngine;
using System.Collections;
public class ColliderBugFix46rc1 : $$anonymous$$onoBehaviour {
void Start () {
collider2D.enabled = false;
collider2D.enabled = true;
}
}
Your answer got sent twice for moderation. Converted second one to comment
Your answer
Follow this Question
Related Questions
Using collider to gameobject detect attack or not 2 Answers
Is it possible to rotate a 2d collider in 3d? 0 Answers
Reset Rigidbody2D rotation after collision 2 Answers
Bug object is shaking in the same spot and object inside another 0 Answers
2D physics settings for solid 2D objects with polygon collider 0 Answers