Making a singleton does not result too well. . .

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

  • This topic has 0 replies, 2 voices, and was last updated 8 years ago by Gavalakis.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #22015
    3d-magic-vr
    Participant

      Hello and good day.

      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.

      #22020
      Gavalakis
      Keymaster

        Hey,

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

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

        3) You now have a “SceneLoaded” event node in the flowscript:
        [attachment file=”SceneLoadedEventNode.png”]

        Let me know if that is indeed what you were after.
        Thanks.

        #22019
        3d-magic-vr
        Participant

          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.

          #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 😉

            #22017
            3d-magic-vr
            Participant

              Thanks, that it’s enough to solve my problem, thanks again, cheers.

              #22016
              Gavalakis
              Keymaster

                Great! I’m glad to hear that 🙂
                Thanks.

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.