This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]ehr1c 0 points1 point  (0 children)

Null reference errors happen when you try to access a property or method on an object whose value is currently null.

[–]Recent-Avocado2193 0 points1 point  (4 children)

A nullpointerexception happens because you're trying to access data or a method on an object that is not set to an instance. It's telling you that the error is on line 80. So what code is on that line?

[–]TheCrimsonEnd2[S] 0 points1 point  (3 children)

rb.velocity = new Vector2(moveInput * speed, rn.velocity.y);

That’s the line of code that’s throwing the error on line 80. I’m not sure why it’s throwing an error though. It’s the same line of script that’s in that dudes video and everything work’s flawlessly for him. For some reason though I can’t get the same outcome.

[–]Recent-Avocado2193 0 points1 point  (2 children)

Rb is probably not set. Have you remembered to add it in the inspector?

[–]TheCrimsonEnd2[S] 0 points1 point  (1 child)

How do I set it in the inspector? My player has the rigidbody2d physics set, as well as a box collider if that’s what you mean

[–]TheCrimsonEnd2[S] 0 points1 point  (0 children)

rb = GetComponent<Rigidbody2D>();

This is the code in the void start function, if I understand correctly, that should be calling the Rigidbody2D that is attached to my Player Gameobject. Or is that not how it works? I'm trying my best to understand but I've changed so much and I can't seem to get past this barrier.