CharacterJoint swing1Limit limit how to use it in c# ??

Hi
i search and dont found a solution.
For this

public SoftJointLimit swing1Limit ;

CharacterJoint sjoint=    gameObject.AddComponent<CharacterJoint> (); 
            gameObject.GetComponent<CharacterJoint>().connectedBody = col.rigidbody;

sjoint.swing1Limit.limit=swing1Limit;

how to give them a value ??
I use int float … but it say it cant use it ??
I want to change the value of swing 1limit under “limit” in character joint???

Pls help me thx

Ps:
This are the erros
“Cannot modify a value type return value of `UnityEngine.CharacterJoint.swing1Limit’. Consider storing the value in a temporary variable”

You pass it a SoftJointLimit Struct.

Structs are value types.

CharacterJoint.swing1Limit is a Struct of type SoftJointLimit.

The code sjoint.swing1Limit returns a copy of the struct that’s already there (like accessing a number value) so trying to assign a sub-property is correctly an error in your code.

Unity should really make they structs immutable so you get a more sensible can not assign read only error but they don’t, hence the confusion.

Just create a new SoftJointLimit with the values you want then sjoint.swing1Limit = myNewSoftJointLimitStruct;

3 Likes

@Cameron_SM Structs are value types. Other than that, thumbs up.

1 Like

Of course they are, please ignore my brain fart. Edited and fixed.

hit thx you do you have a c# code for the struct ??
Thx

Just say “sjoint.swing1Limit = new SoftJointLimit(” and IntelliSense should give you some constructor options. 90% of the time when faced with a new class or struct type that I’m not familiar with, I use IntelliSense as a guide. Looking up every single thing in the documentation would be slow, and a lot of the details simply aren’t there anyways. Any existing constructors will pop up in the list and give you an idea of how to go about doing it.

In short, unless someone here has the options memorized (doubtful), that’s exactly what they’ll do to find you the answer. So, you may as well give it a shot yourself.