Accessing a variable that has a unique class

this is a portion of my animation code:

	function Start () {
	var motor : CharacterMotor = gameObject.GetComponent(CharacterMotor);
	animation["idle"].wrapMode = WrapMode.Loop;
	animation["jump_pose"].wrapMode = WrapMode.ClampForever;
	animation["walk"].wrapMode = WrapMode.Loop;
	animation["run"].wrapMode = WrapMode.Loop;
	}

	function LateUpdate () {
		charVelocity = motor.movement.velocity;
		CalculateState();
		ApplyState(); 
	}

My problem is in the line “charVelocity = motor.movement.velocity;” it says Unknown identifier ‘motor’ (BCE0005).

Movement is a variable with a class of its own and I am trying to access the velocity part of it after the code has run in the other script.

You declare motor in Start() and then reference it inside LateUpdate() which is outside of its scope, hence the “Unknown Identifier” error - it doesn’t exist there. You need to declare motor as a class variable, so that all methods of the class can access it.

Your problem is, that you’re trying to access a variable that doesn’t exist. On line 2 in Start you declare a variable motor of type CharacterMotor. Since the variable is declared inside of a function, it will only exist during that function and will be freed once the function returns. It doesn’t exist anymore when you try to access it in the Update function.
To fix this, you should make the motor variable a private variable on your MonoBehaviour class. Class variables (fields) exist as long as the object they are part of does.

class SCRIPTNAME extends MonoBehaviour {
    private var motor:CharacterMotor;
    
    function Awake() {
        #This is the fastest method of GetComponent
        motor = GetComponent(typeof(CharacterMotor)) as CharacterMotor;
    }
    
    function Update() {
        #Yay, it exists here too!!
        Debug.Log(motor);
    }
}