ConfigurableJoint JointDrive not being set <SOLVED>

Hi, I have the following on Start()…

GameObject ch = GameObject.Find("character_hand");

JointDrive jd = new JointDrive();
jd.mode = JointDriveMode.Position;
		
jd.positionSpring = 20f;
jd.positionDamper = 20f;

ch.GetComponent<ConfigurableJoint>().angularXDrive = jd;
ch.GetComponent<ConfigurableJoint>().angularYZDrive = jd;

and when looking in the editor whilst running the scene the inspector for “character_hand” shows the correct angular X + YZ Drive values as set by the code, however this does not seem to have any effect on the physics engine in the game, it seems to be using the original values as set in the editor not the values assigned from code that are now visible in the inspector.

Am i doing something wrong?

Any help appreciated!

Thanks

The values you set in the inspector override the values of your code when you initialize the variables.

Was this the problem :?:

It certainly seems that way. but when i look in inspector during scene play my variables are assigned to the joint drive they just dont seem to change the behaviour of the joint, very strange!

I wonder if it is even possible to alter the joint drive of an existing joint or if i need to add the connectedbody after assigning the joint drive.

I will experiment with this today and post back my findings.

GameObject ch = GameObject.Find("character_hand");

JointDrive jd = new JointDrive();
jd.mode = JointDriveMode.Position;
		
jd.positionSpring = 20f;
jd.positionDamper = 20f;

ch.GetComponent<ConfigurableJoint>().angularXDrive = jd;
ch.GetComponent<ConfigurableJoint>().angularYZDrive = jd;
ch.GetComponent(ConfigurableJoint>().connectedBody = ch.GetComponent<ConfigurableJoint>().connectedBody;

Reconnecting the rigidbody to connectBody seems to do the trick, however this will take the current position state as the new center, not a problem for me working on Start() however if you were wanting to change the joint drive whilst running the scene this might not give the desired results.