Hello Unity3D Community,
first of all, I know there are like 100 Questions about this Error.
I’m still not able to fix it.
The Error shows up in this line of code.
PlayerWeapons PlayerWeaponsComponent = GameObject.Find("FPS Player").GetComponent<PlayerWeapons>();
FPS Player is a Prefab attached to the Prefab Player, the Script PlayerWeapons is attached to FPS Player.
The Prefab Player gets spawned / created later on Ingame (Clone)
Thanks for the Help (:
Your sincerely,
Pwnographyz
You would not get a null reference exception if you tried to do “GetComponent” for a component that was not found on a GameObject. It will simply return null. The null reference exception is coming from the fact that there (apparently) is no GameObject called “FPS Player”. Check to ensure that you are using the exact name of the GameObject you are trying to find, and that it, in fact, exists when you make that call.
Try using the “error pause” option on the console, in the Unity Editor to ensure that the exact frame that the error occurs on is when you are checking to ensure that the GameObject is there.