|
I'm getting the following error: "NullReferenceException: Object reference not set to an instance of an object Ai_Controller.AiInitHeading (.Player_Controller ai, System.String dir, System.String deg) (at Assets/Scripts/Ai_Controller.cs:27) Input_Controller.InputEnter () (at Assets/Scripts/Input_Controller.cs:468) Input_Controller.Update () (at Assets/Scripts/Input_Controller.cs:174)" Basically, I declare a variable and load it with a C# script component (Player_Controller.) I then pass that component to Ai_Controller.AiInitHeading() As you can see, the object the Player_Controller component is attached to doesn't seem to make the transition to the function. Is there some step to passing a script component in a function that I'm overlooking? AiInitHeading declaration looks like: AiInitHeading( Player_Controller ai, string dir, string deg )
(comments are locked)
|

Can you post the whole function?
And can you look up the line 27 where the error occurs because we can't count the lines if we don't know where to start. There's nothing special you have to take care of. A reference to an object behaves like every other value. Just pass it to the function.
If you can't find the error start debugging. Just use Debug.Log and print all parameters you pass to the function to see if it's null. If it's null you have to go up the chain and find out why it's null. If it's not null you have to go down the chain.
This function is declared inside a class Ai_Controller which inherits from Monobehaviour but is not added to any object as a component.
It get's called like so from some object's component script:
Where mPlayer is declared as:
With other member variables and initialized in Start() as:
I see two possible reasons:
GetComponent< Player_Controller >();returns null because there is no such script attached to this GameObject.QueOrdersHeadingvariable inside your Player_Controller script has not been initialized.It turns out when I dragged the Player_Controller component onto the object-- I missed :P But in such a way that I was happily looking at the wrong object going "the component is right THERE, you stupid console!"