- Home /
public text prefab goes null after scene switching,Text prefab is null after reloading the scene
I have two scenes that are managed by code. Within the first scene, I have a concept of a Game Manager which is a singleton supported by a DoNotDestroy() method. The GameManager holds a reference to a TextManager which holds a reference to a Text Prefab.
The text Prefab attribute is not modified by code, but it does get utilized by the following code:
txt.go = Instantiate(textPrefab);
after which, we get an error: Object reference not set to an instance of an object
for some reason, the drag and drop approach for my Text Prefab only works when I run in the scene. But if I change out of the scene and back into the original scene, this reference goes null (confirmed by the following log):
Debug.Log("textPrefab is null: " + (textPrefab == null));
Game Manager where the Text Manager sits:
Text Manager, where the prefab that goes null sits:
So the question is:
1) Why is the drag n drop approach not sustaining itself within the scene?
2) How do I get it to stay regardless of scene changing?
3) Should I be referencing the Prefab by code instead of drag/drop? If so how?
Your answer
Follow this Question
Related Questions
The prefab you want to instantiate is null. Tried googling, didn't help. 1 Answer
Clone a prefab 1 Answer
Can't retrieve information from GameObject 2 Answers
Some Prefabs are not Loading 1 Answer