Nifty GUI instancing

Hi Guys,

I have an issue with instancing in nifty gui.

I have setup my game so that if a game is started (from my start menu) a Nifty GUI is created from scratched. When the game is ended I close and recreate Nifty and the NiftyJMEOverlay.

The problem is that old objects which subscribe to the old Nifty object via [java]nifty.subscribeAnnotations( this );[/java] is still triggering to nifty events setup through [java]@NiftyEventSubscriber( id = “console” )[/java] - even though they should be subscribing to a whole new nifty instance.

This results in events triggering equal to the number of games I have opened closed in one session…

Is the nifty object or its eventbus using a singleton internally?

I guess the obvious solution would be to only init my gui once, which would be a major rewrite, adding post init binding of the gui to a game instance.

Yes, Nifty uses singletons.
Nifty isn’t built for being shut down. If you can, just switch between screens (and use an empty screen to “switch Nifty off”).

1 Like

I feared this was the case, thank you @toolforger.

I guess I am up for a few days of rewriting gui initializations…