Reply To: Making a singleton does not result too well. . .

FlowCanvas Forums Support Making a singleton does not result too well. . . Reply To: Making a singleton does not result too well. . .

#1701
Gavalakis
Keymaster

Hello again,

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.
ButtonGraph

2) The singleton patter can be done as such in the Manager Awake.
SimpleSingleton

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.
LoadSceneEvent

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.
SceneLoadedEvent

Let me know if the above help.
Thanks 😉

Join us on Discord: https://discord.gg/97q2Rjh

Attachments:
  1. ButtonGraph.png

  2. SimpleSingleton.png

  3. LoadSceneEvent.png

  4. SceneLoadedEvent.png