I’m pretty sure this is a quick fix.
I have a group of prefabs that need to reference a GameMaster script in an Awake function. The GameMaster script is consistent through all my scenes.
How can I…
- Check for an existing GameMaster script
- If it exists, assign it to the prefab as a variable
Thanks for your time!
Sorry, this seems to happen every time I ask a question. It was a really simple fix that had me pulling my hair out.
I found a different way to solve my problems!
From within the GameMaster script, I was calling a DontDestroyOnLoad and a Destroy operation.
It searched through my Scene, checked if a GameMaster script existed, and destroyed it if it did. The solution was to use a SetActive(false) operation instead!!
Here’s the script, in case someone else is having a similar issue.
public static GameMaster Instance;
// Start is called before the first frame update
void Start()
{
if (Instance == null)
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
else if (Instance != this)
{
gameObject.SetActive(false);
}
}