Hinge joint motor bug?

I was trying to change the speed on a hinge joint and had to settle on this code:

public class JointController : MonoBehaviour {
	JointMotor hingeMotorThing;
	
	void Start () {
		this.hingeMotorThing=gameObject.GetComponent<HingeJoint>().motor;
	}
	
	void Update () {
		if(Input.GetKey(KeyCode.LeftArrow)) {
			Debug.Log("Moving left");
			this.hingeMotorThing.targetVelocity = -10;
		}
		if(Input.GetKey(KeyCode.RightArrow)) {
			Debug.Log("Moving right");
			this.hingeMotorThing.targetVelocity = 10;
		}
		//had to add this line or nothing would happen
		gameObject.GetComponent<HingeJoint>().motor=this.hingeMotorThing;
	}
}

this.hingeMotorThing=gameObject.GetComponent().motor; 

seems to just clone the Motor instance. Is this intentional? Using something like

 gameObject.GetComponent().motor.targetVelocity = 10;

Also wouldn’t work as it says the value is read only.

I want to add that according to this
scripting manual reference
I shouldn’t have had to do this strange “hack”.

I realize this is old, but could still help others…

That is the correct method of changing a motor on a hinge joint, it’s not a hack. The motor is a property inside the hinge joint, so it’s members cannot be accessed directly. Think of it as a getter/setter and it will make sense. Another example in Unity is a transform’s position: a Vector3, but you must read the vector, assign it to a local variable, modify it, then assign it back to the position member to affect a change. Somewhat annoying at first, but it’s like that so that the internal transform code can do other stuff when you poke about with its data.