playMaker

Author Topic: Singleton Manager  (Read 1304 times)

Dakk

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 21
Singleton Manager
« on: August 16, 2017, 01:11:40 PM »
I've searched the forums and couldn't find an answer, there is probably an easy/obvious one I am missing.

I use the singleton manager to prevent duplicates on my controllers as the game moves through different scenes (I have dups so that the game can be run from any scene without having to start at the title screen).  This works fine. 

The problem arises in that I have these controllers define themselves (get self) and store as global game object variables so that other FSM's can access them.

On scene load, the singleton manager destroys the original game object, which causes the controller to lose its global var game object assignment.  So I add an action for the controller to re-define itself after any level load.   

This doesn't work well, it requires a loop as the self-definition fails silently as the first step after level load.  So I have to check if it is null and loop (get self) until it gets defined.   This works, but causes a cascade of timing issues, as I can't rely on that controller being defined in the first few frames after load.  I am also concerned that the timing is not deterministic and could vary per user so it may cause some hard to track bugs in the wild.

If the singleton manager resolved duplicates by destroying the object in the NEW scene- instead of the one that is already in use, I think it would avoid all of these problems and my global variable game objects would stay defined.

Maybe there is another pattern I should be using.  Any help appreciated!
Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Singleton Manager
« Reply #1 on: August 17, 2017, 12:49:06 AM »
Hi,
i have not used singleton yet but i can find the issue.

Can you show this on a video or animated gif
showing your fsm/states/actions/variables/what happens when played and anything that might be usefull




jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Singleton Manager
« Reply #2 on: August 17, 2017, 04:11:26 AM »
Hi,

 this is not how it's supposed to work, the singleton manager destroy the new instance created, not the old.
 

 are you sure you have set to not destroy on load the Go you want to be a singleton?

 Bye,

 Jean