I create a ragdoll, procedurally, using capsules and configurable joints. The joints can break if there is an impact above a certain force. I’m setting breakForce in the joints to enable that. I’m using the built in unity function "OnJointBreak(float breakForce); to trap the breaking and create various effects if it happens, and that works OK, but each capsule has two joints and this function doesn’t tell me which of the two joints has broken. For my code to work properly I need to know this. I read the physX documentation and the callback that physX generates on a joint break does contain this information. Is there someway of getting it in Unity?
I came across this the other day and I don’t think there is a callback that tells you exactly which one was it (you get the callbacks for both joints in the script in the capsule).
But you can create a small component that you add on each joint and then tells the capsule script about the event and the information that you want
//JointEvent.cs
//Optioan A
public Action<float> OnJointBreak;
//Option B
public Action<float,Joint> OnJointBreak;
I am not certain how you call leftJoint.AddComponent. The method is only available on GameObject, so adding a component to the joint is hardly possible.