I got this problem when I tried to replicate a singleton effect and using the SceneManager.sceneLoaded delegate (There’s an attached package with the scene and the json to recreate the flow).
The issue happens when the next level is pressed, I really don’t know why this happens (the logic it’s quite simple), all seems to work fine, just he fact that there must be only one object instance, hopes this it’s just about a miss understanding from my part, have a nice day, cheers.
From the inimaginable and beyond, where the mind feels free.
I’ve downloaded your attachment, but I am not exactly sure what you want to achieve 🙂
Are you basically trying to get a callback for whenever a Unity scene is loaded (thus the ‘SceneManager.sceneLoaded’ event is raised) ?
If so, you can do so in an easier way:
1) Open up Preferred Types Editor window and add the “UnityEngine.SceneManagement.SceneManager” type in the types list.
2) Doing the above, you can now use the SceneManager API, like for example directly make use of the ‘sceneLoaded” event. Browse or search for the sceneLoaded event:
3) You now have a “SceneLoaded” event node in the flowscript:
Let me know if that is indeed what you were after.
Thanks.
Hello again, that’s not what I mean, only you have to do it’s check the scene what it’s inside the attached package, recreate the flow controller using the included json file, hit the play button and click on the button that says “Next Level”, what I’m trying to do it’s the same effect like a singleton (just one instance can remain when reloading the same scene), and sorry about the duplicated post, I had some sort of trouble with my internet connection and I don’t notice that the site creates the first post and it only has the image and when I submit again the second one has only the package (which had to be into the first post :-D), so, I still have the same problem and can’t solved yet, thanks for your time and have a nice day, cheers.
From the inimaginable and beyond, where the mind feels free.
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.