I’ve taken your example and modified it only to leave what is necessary for the singleton pattern to work. Following is one way of doing what you are after (tested and works with your example scene).
1) First of all, the UIButton flowscript does not need to use FindObjectOfType, since the Manager is stored in the GlobalBlackboard.
2) The singleton patter can be done as such in the Manager Awake.
3) Tthis is the event send from the UIButton, for the shake of demonstration. For testing purposes, I’ve also made a local variable, which increase by +1, each time the event is called.
4) Finally, it’s best if you use the “SceneLoaded” event (Reflected/SceneManager/SceneLoaded (AutoSubscribe)). Notice that before doing anything, it’s best to always check, if the current “instance” of Manager stored in the GlobalBlackboard, is our-self and only then continue in finding the UIText and setting it’s text.
Let me know if the above help.
Thanks 😉
Join us on Discord: https://discord.gg/97q2Rjh
Attachments:
ButtonGraph.png
SimpleSingleton.png
LoadSceneEvent.png
SceneLoadedEvent.png
Login
Register
By registering on this website you agree to our Privacy Policy.