Scripting Gravity 2/8 Tutorial - Code error

Hi, I’m having a problem with the Scripting Gravity [2/8] tutorial:

I get the following error in the console:

NullReferenceException: Object reference not set to an instance of an object
PhysicsObject.Movement (Vector2 move) (at Assets/PhysicsObject.cs:40)
PhysicsObject.FixedUpdate () (at Assets/PhysicsObject.cs:35)

I can’t see how my code differs from the example:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PhysicsObject : MonoBehaviour {

    public float gravityModifier = 1f;

    protected Rigidbody2D rb2d;
    protected Vector2 velocity;

    void onEnable()
    {
        rb2d = GetComponent<Rigidbody2D> ();
    }

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
       
    }

    void FixedUpdate()
    {
        velocity += gravityModifier * Physics2D.gravity * Time.deltaTime;

        Vector2 deltaPosition = velocity * Time.deltaTime;

        Vector2 move = Vector2.up * deltaPosition.y;

        Movement (move);
    }

        void Movement(Vector2 move)
    {
        rb2d.position = rb2d.position + move;
    }

}

Using Unity 2017.1.0f3 personal.

I found the problem - Line 12void onEnable()Should be a capital ‘O’ at OnEnablevoid OnEnable()So the rb2d variable wasn’t being assigned, as OnEnable wasn’t doing anything, and onEnable was never called.

A swine to track down, but taught me a few things. Onwards and upwards!

had the same issue lol feel like an idiot :stuck_out_tongue: