Hey there,
so as a beginner in Unity, i started following the Roll a Ball tutorial, But I encountered a bug I couldn’t seem to solve while adding the movement forces, I’m pretty sure I made each step correctly and checked my code a few times, here is the bug :
NullReferenceException: Object reference not set to an instance of an object
Player_controller.FixedUpdate () (at Assets/Player_controller.cs:19)
and here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Did you add a rigidbody to the object? Also, read the first thread in this forum about using code tags, and always show the line that is causing the error, we don’t know what line 19 is. Since there isn’t much there, I’m guessing you didn’t add a rigidbody.
Out of curiosity Mysgym, what editor are you using? Because most editors when you type void start, they will offer code completion so you don’t make mistakes like that.
I use monodevelop, it does offer completion but I started coding with HTML JS and I used the bloc note. So I’m not used to autocompletion and prefer writing. Even though it creates those problems…
Those kind of mistakes are hard to see. You are lucky metos5k spotted it. It is so easy to make a typo and hunting it down can be murder. Just for variables, and method names I would highly recommend rethinking that. Not only that, but it can tip you off you are on the wrong track when the option you want doesn’t appear. You may have forgotten an include. It’s hard enough finding logic errors without looking for typos. As far as the compiler is concerned, you just wrote another method that started with a non-capital “s”, so there is no tip off and that’s why you were here thinking it was a bug.