Search Unity

Null Reference Exception: Object reference not set to an instance of an object

Discussion in 'Scripting' started by OthmanJb, Feb 27, 2015.

  1. OthmanJb

    OthmanJb

    Joined:
    Feb 22, 2015
    Posts:
    1
    Hello. Let me be precise, im new to scripting and game programming and i have this book titled "Game Programming Using Unity 3D" im following to build a simple zombie game. But as i reached to where i am to add the walk animation to my 3D model and control it using script, i followed the exact steps given in the book but when i try playing it, it showed me the below code in the console:
    Null Reference Exception: Object reference not set to an instance of an object, in this line:

    How can i solve this?


    usingUnityEngine;
    usingSystem.Collections;

    publicclassEnemyAnimation : MonoBehaviour
    {
    Animation Animate;

    voidStart ()
    {
    Animate = GetComponentInChildren<Animation> ();

    Animate ["Move1"].wrapMode = WrapMode.Loop; // line where the exception shows
    Animate.Play ("Move1");

    //Move1 is the name of the animation to play for the walk
    }
     
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Verify that you gameObject or the child that should has the Animation component in whatever child it should have.