Assigning a unity component variable issue

I’m using Unity 3 and I’m trying to perform a simple assignment of the variable linearLimit>limit within the ConfigurableJoint component. I’m using the code below but I keep getting the error “Cannot modify a return value, try placing it within a variable first”. Am I doing something wrong?

//My Code

ConfigurableJoint cj = gameObject.GetComponent();
cj.connectedBody = objectToGrab;

	cj.xMotion = ConfigurableJointMotion.Limited;
	cj.yMotion = ConfigurableJointMotion.Limited;
	cj.zMotion = ConfigurableJointMotion.Limited;
	
	float newLimit = 1.0f;
	cj.linearLimit.limit = newLimit;

//Unity’s public Accessor/Mutator for that variable

public float limit {
get {return this.m_Limit; }
set {this.m_Limit = value; }
}

Hi

to set a configurable joint limit you have to:

ConfigurableJoint cj = gameObject.GetComponent();
cj.connectedBody = objectToGrab;

cj.xMotion = ConfigurableJointMotion.Limited;
cj.yMotion = ConfigurableJointMotion.Limited;
cj.zMotion = ConfigurableJointMotion.Limited;

// setup a SoftJointLimit instance to modify...
SoftJointLimit newLimit = new SoftJointLimit();
newLimit.limit = 1.0f;
newLimit.*otherVars* = cj.linearLimit.*otherVars*; // if needed
// ... and set the joints limit to the SoftJointLimit instance
cj.linearLimit = newLimit;

hope it helps :wink: