why does not want to work ?? Code (CSharp): private Rigidbody two_rb; GameObject obj; void OnCollisionExit(Collision exit) { two_rb = obj.AddComponent<Rigidbody>(); }
Not sure of your full codepath and object setup, but I see you are adding a Rigidbody... if you don't already HAVE a Rigidbody, none of these collider/trigger functions will be called. See the docs: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionExit.html I quote: "Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."
I already understood this. Can I somehow solve this? when the object touches terrain the rigidbody is deleted and when it no longer touches then I need to add the rigidbody back, with OnCollisionEnter everything is fine with me, but it doesn’t work with OnCollisionExit
Can you just set the Rigidbody to be isKinematic (on initial collsion) instead of deleting it? That's usually the way you take things out of the Physics simulation if you intend to put them back in later... Alternately maybe you can have a proxy invisible collider object whose Rigidbody you DON'T delete, and that has connections over to your current object, but that can get a little bit tricky.