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

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

#22018
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.
    [attachment file=”ButtonGraph.png”]

    2) The singleton patter can be done as such in the Manager Awake.
    [attachment file=”SimpleSingleton.png”]

    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.
    [attachment file=”LoadSceneEvent.png”]

    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.
    [attachment file=”SceneLoadedEvent.png”]

    Let me know if the above help.
    Thanks 😉