hey, how can i change the lowTwistLimit.limit on a character joint to zero?
gameObject.GetComponent<CharacterJoint>().lowTwistLimit.limit = 0;
but that results in “Cannot modify a value type return value of `UnityEngine.CharacterJoint.swing1Limit’. Consider storing the value in a temporary variable”
lowTwistLimit is of type
[SoftJointLimit] which is a
struct. So you can not modify just a single value of it as you are trying to do. This is similar to what happens when you try to update just one value of a transform’s position since position is a Vector3 which is a struct. So you need to build a new struct with your desired values and assign it. Something like:
CharacterJoint charJoint = gameObject.GetComponent<CharacterJoint>();
SoftJointLimit jointLimit = charJoint.lowTwistLimit;
jointLimit.limit = 0;
// Here we assign the updated struct back to lowTwistLimit of character joint.
charJoint.lowTwistLimit = jointLimit;