-1

This error message keeps showing everytime I test the game:

NullReferenceException: Object reference not set to an instance of an object SetupLocalPlayer.Start () (at Assets/Scripts/SetupLocalPlayer.cs:12)

and I'm trying to figure out how to enable my Wheeldrive script when I am the local player (When I spawn in) and it doesn't seem to be working, The Network Id is on the player prefab but the controller script is on the Sedan gameobject, since the Network identity is on the player prefab the disable script also has to go on it, so I don't think the script is able to find the controller script since its not on the same Gameobject. (Picture Below)

Any help is really appreciated :) The Project + Code Picture

  • SetupLocalPlayer.cs code would be nice. – Karolis Jc May 17 '17 at 14:42
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Hellium May 17 '17 at 17:11

2 Answers2

0

If the SetupLocalPlayer script is on the player prefab, You should be able to find the WheelDrive component using GetComponentInChildren<WheelDrive>() instead of GetComponent<WheelDrive>() (in line 12 of the SetupLocalPlayer.cs file)

Basile Perrenoud
  • 4,039
  • 3
  • 29
  • 52
0

Because the WheelDrive component is not enabled, GetComponent is unable to find it. Thus GetComponent<WheelDrive>() returns null, and you get the error in the console.

Hellium
  • 7,206
  • 2
  • 19
  • 49