NullReferenceException: Object reference not set to an instance of an object

A couple of things first; a more appropriate forum to post about a scripting problem is the scripting forum. Also, when posting code, always use code-tags please rather than plain text. Finally, when you have an error, always post the full error including the line/column which it tells you in brackets.

A NullReferenceException in C# means exactly that; you’re using a reference (a class reference) but it has not been assigned so it’s NULL by default.

Looking at the above, it’s likely it’s telling you the error is on this line:

rigidBody.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);

… because you create a reference of “rigidBody” above it but you don’t assign anything to it. Well you “sort of” do here:

void Aweke()
{
    rigidBody = GetComponent<Rigidbody2D>();
}

… but this is never called by Unity because you’ve mis-typed it. It’s “Awake” not “Aweke” so it’s never assigned.

1 Like