Search Unity

Null reference exception on my animator in network

Discussion in 'Scripting' started by Deleted User, Nov 9, 2016.

  1. Deleted User

    Deleted User

    Guest

    When I run this script

    void OnTriggerEnter (Collider other)
    {

    print("should TZ now");
    foreach(AnimationClip ac in myAnimator.runtimeAnimatorController.animationClips)
    {
    print(ac.name);
    }

    }

    I get this on the console:

    http://imgur.com/a/ktyac

    and the foreach line gets the null reference exception.

    There are no problems in single player mode, this only occurs on the network. Can anyone explain this to me? Thanks in advance for your patience.
     
  2. Deleted User

    Deleted User

    Guest

    I guess I'll just put in a test for myAnimator != null (and that works) but doesn't explain the error... Oh well.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Those printed statements are coming from the foreach loop, so it's not "myAnimator" that is null. It is one of the elements in the "animationClips" list that is null. You should check for "ac" being null before accessing the name, or figure out why its null.

    Whatever comes after "Kote Block" is null in the list.