i don't understand "NullReferenceException: Object reference not set to an instance of an objec"

Hello so i try to understand by searching “NullReferenceException: Object reference not set to an instance of an object” on google but i didn’t find my answer so everytime i click on play this message is spamming the console, I’m trying to put animations of a character in a script (Idle, Run, Walk,…)

there is my Script:

//Public variables
var speed:float;
var speedRun:float;
var speedRotate:float;
var gravity:float;

//Private variables

private var controller:CharacterController;
private var moveDirection:Vector3;
private var deltaTime:float;
private var characterContent;
private var runAnim:boolean;

function Start () {
     controller = GetComponent("CharacterController");
     characterContent = transform.find("Perso");

function Update () {

    //Cadence du temps
    deltaTime = Time.deltaTime;
    //On ne cours pas
    runAnim = false;
    //Deplacements Haut/bas
    if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)){
        moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speedRun);
        runAnim = true;
        moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speed);
    if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow)){
                characterContent.animation.CrossFade("Walk", 0.2);
                characterContent.animation.CrossFade("Run", 0.2);
        characterContent.animation.CrossFade("Idle_01", 0.2);
    //changer sur l'axe
    moveDirection = transform.TransformDirection(moveDirection);
    //rotation personnage
    transform.Rotate(Vector3(0,Input.GetAxis("Horizontal") * speedRotate * deltaTime,0));
    moveDirection.y -= gravity;
    //Deplacement du Character Controller    
    controller.Move(moveDirection * deltaTime);

So The error seems to be on the line 45 (in MonoDevelop)or line 23 (on this topic) which is " characterContent.animation.CrossFade(“Idle_01”, 0.2);"
Tne animation of the idle is called “Idle_01” on unity so i don’t understand where the error came from …
If someone can help me it would be great !

NullReferenceException: Object reference not set to an instance of an object mean you trying to access an object that not been assigned (null) , make sure the animation is attached to your game object character :slight_smile:

haha i see it now , change this line to this :

characterContent = transform.find("Perso");

//change it to this line 


Make sure your script is attached to the parent object Glem :slight_smile: