[Solved] Getting root nodes from appstates

So the usual way for me to get the guinode or rootnode is usually via boxing Application from within initialize or something, which is perfectly fine, or bring an object with me from the constructor. Or maybe even just box with Main.class - there are options aplenty.

But in developing extensions for a general audience you cannot guarantee they use SimpleApplication or have a method ‘getGuiNode()’ in their Main class. You do have guaranteed viewports though from Application. These return a list of spatials, so you cant really guarantee the first object will be what you want.

So my question is how do you get at these objects reliably?

You could provide an abstract AppState with abstract getters and let the user provide this methods in their own implementation. They have of course to add this state first… You can even provide a default “provider state” for SimpleAplication. Or you add setters or use a factory/constructor with argunents to your Appstate.

You are thinking too complex, just add the rootNode param to your Constructor.

Especially when you dont know what the Users want to do with it like only applying it to a sub gtaph

I was kind of hoping for a more self-contained solution rather than having to require a couple of nodes in the constructor each time… it would mean the user would have to carry them around too.

Edit: And in looking at scene processors and such, they just presume that the list is created and iterates over them all.

This is how I do it:

The thing is that guiNode/rootNode are kind of arbitrary. Someday you were supposed to be able to grab a app state to get them (part of the application refactoring that hasn’t happened yet)… but in the end some user may be using a custom viewport with their own nodes (the point of breaking things out into app states in the first place).

It’s a bit rude to force them to use the JME provided ones in that case.

1 Like

Thank you.