- Home /
In the tutorial of the 2D Roguelike game, where is the player gameobject instantiated in the code?
The player character is not instantiated on any levels.
I tried changing between levels with and without enemies, but still not instantiated. When an enemy is instantiated in the level the following error message shows up:
NullReferenceException: Object reference not set to an instance of an object Enemy.Start () (at Assets/Scripts/Enemy.cs:14
This error message shows up as many times as there are enemies on the board.
I have gone through the tutorial videos from start to finish several times now, but I cannot find where the player is actually spawned into the level. What am I missing?
Answer by another_kind · Apr 27, 2015 at 02:28 PM
In the beginning of part 8, he puts the player prefab in the hierarchy, I think it stays there from that point, which means the player doesn't have to be instantiated in the code.
Ah, I missed that. Thank you, but I still get the error message and my character won't move.
The character is animated, but doesn't react to pressing keys. I double checked the code component, correctly spelled, but still doesn't respond. I even copied the code from the completed script, but still the same error message.
I'm having the same problem. The player doesn't react to keypresses. I tried using only completed scripts, yet I still got the same error message spammed continuesly.
NullReferenceException: Object reference not set to an instance of an object Player.Update () (at Assets/Scripts/Player.cs:32)
I haven't even started on part 10. Writing the Enemy Script yet. I've been stuck here for hours.
Answer by Simpso · Jun 12, 2016 at 12:18 PM
I had the same issue until i realized my mistake in the Game manager script.
Turns out i wasn't setting the instance of the game manager because of a simple bit of syntax. Coming off the back of coding in VBA where a if statment uses one = , i had missed the c# way of doing things.
Basically the double == was missing from the the below code .
Check that to see if it solves your issue. @wolfcamoedsheep @nickazoid
void Awake() { if (instance == null)
Your answer
