- Home /
Instance is null only in playmode?
I am making a game where an object (3d text) is instantiated every time score is added, at the position of the gameobject wich gave you the score.
My problem is that a specific prefab is bugging; the 3d text is set in the gameobject's prefab and the text is a prefab itself so there shouldn't be a problem. Plus, in step by step, everything works fine and the variable for the instance is never changed during the game.
but in normal playmode, I get this error every time even tho the gameobject had the reference the whole time.
Can you post the code?, is the text prefab associated correctly with the script?
particulesInstance = Instantiate(particules); particulesInstance.transform.position = transform.position; ScoreInstance = Instantiate(scoreDisplay); ScoreInstance.Score = 500; ScoreInstance.transform.position = transform.position; score$$anonymous$$anager.Score += 500; Destroy(gameObject);
the problem could be that my object is being destroyed, but the particules works the same way and never had that problem even tho the object was being destroyed because it doesn't need more than one frame to exist.
I even distanced the time before being destroyed without any results exept that I could look at the object trying to instantiate while still having the reference. Still not working.
Answer by jmailloux11 · Apr 18, 2020 at 10:26 PM
Forget about it, it seems to have fixed itself... I didn't did anything nor reopened the project and it still magically fixed itself. Thanks anyways.
Your answer

Follow this Question
Related Questions
got null reference when trying to access script from instantiate object 1 Answer
Checking if object intersects? 1 Answer
Null Reference Exception transform position y 2 Answers
I have never seen a null reference exception like this one! 1 Answer
assign different values to prefabs on instantiation 2 Answers