NullReferenceException!! help!!

Hi,
unity and programming newbie here.
I’m toying around with unity trying to make a 2d project
so I made a sprite, and I set an running animation for it. the problem is my sprite wont move when I hit play, and if I remove some line in the script i’ll be able to move it but the animation wont trigger.
I get the error “NullReferenceException: Object reference not set to an instance of an object
player_movement.movement () (at Assets/player_movement.cs:20)
player_movement.Update () (at Assets/player_movement.cs:16)”

here is my script

using UnityEngine;
using System.Collections;

public class player_movement : MonoBehaviour {

public float speed;
        
            Animator anim;
        
        	void start() 
        	    {
        				anim = GetComponent<Animator>();
        		}
        
        	void Update () {
        		movement();
        	}
        	void movement()
        	{
        		anim.SetFloat("speed", Mathf.Abs(Input.GetAxis ("Horizontal"))); // this is the line that im talking about
        
        		if (Input.GetAxisRaw ("Horizontal") > 0)                                   
        		        {
        						transform.Translate (-Vector2.right * speed);
        						transform.eulerAngles = new Vector2 (0, 180);
        				}
        		                                                  
        		if (Input.GetAxisRaw ("Horizontal") < 0) 
        		        {
        						transform.Translate (-Vector2.right * speed);
        						transform.eulerAngles = new Vector2 (0, 0);
        				}
        		}
        	}

Your start method is spelled with a lower case “s” so it probably never gets called, thus leaving “anim” null.

    void start() 
    {
        anim = GetComponent<Animator>();
    }

should be

void Start()
{
    anim = GetComponent<Animator>();
}

@justin35f

oh, haha! done. thanks :smiley: