Script finds everything but still i get "nullreference, object not set to an instance of an object"???

Hi everyone, this is my script, it prints everything correctly, so everything seems to be recognized and found, but when i want to play the animation of “Bird” i get a null reference exception “Object not set to an instance of an object”, even though it prints the bird as gameobject bird! i’m very confused! how can that be? Maybe it has something to do with the fact, that the script is on a empty sprite and the object “Bird” is a child of the sprite?
Has someone any idea?

var Baby : GameObject;
var BabyPosz : float;
var animationToolkit;
var Bird;

function Start () {

Baby = GameObject.Find("baby");
Bird = GameObject.Find("bird");
animationToolkit = gameObject.GetComponent("tk2dAnimatedSprite");


function Update () {

BabyPosz = Baby.transform.position.z - 3.7;


if(transform.position.z < BabyPosz){

You’re mixing the Bird and animationToolkit variables in a non-working way. animationToolkit is your animatedSprite component (not your child’s.) You can use it as-is: animationToolkit.whatever.

When you write Bird.animationToolkit, you aren’t using your animationToolket variable. Instead, you’re using it as a magic word like Bird.transform or Bird.rigidbody. But animtoolkit isn’t a magic words, so you get an error. C# would yell about it directly. Javascript tries to look it up and returns null.

You might mean to say: animationToolkit=Bird.GetComponent.... But, GameObject.Find("bird") isn’t for finding children – it finds a different top-level gameObject. Maybe you also want transform.Find("bird"), to find your child bird.