Hi,
I have a singleton that it attached to a gameObject that hangs on runtime below the DontDestroyOnLoad.
I can instantiate it normally from any script that is in the scene with:
states = StateManager.Instance.GetComponent<StateManager>();
But one of the scripts where i want to instantiate the singleton as well, is also located in the DontDestroyOnLoad and with that one the above code doesnt seem to work.
Generally in the singleton pattern, the Instance of something actually IS the component reference. You wouldn’t normally call GetComponent<> again, but I suppose it might be harmless, just extra typing.
In your case, are you perhaps looking for GetComponentInChildren() or GetComponentInParent()?
Yes i was trying to fill the “public StateManager states;” with the values from the statemanager so i can access each one of the values after with “states.IsControllable” “state.GameMode” etc guess its my old way of doing things.
I changed the code to directly access “StateManager.Instance.Iscontrollable = isControllable;” and that seems to work.
thanks a lot for pointing me in the right direction!