General question - attach/detach lights/physics - different approach

Hi,

some time ago i wrote control for “attach/detach physics or lights” based on distance to camera and other factors.

But i had to do tricky way to “detach physics or lights” when node is not child of some rendered parent. (rootNode in this case, controls just stop call update, no other calls when lights are not rendered). To achieve this i needed to have appState controlling from time to time if this controls spatials have rootNode ancestor, if not then remove control from list and node.(and remove related element like rigidBody from physSpace or light from some other node)

Question is, if there is some better solution for this, because this one is … ugly…

i also thought move to into “new appState each time” that will know its spatial related, and if suddenly it dont have rootNode ancestor. But here my clone will not dupplicate this appState.

so generally i ask for some advise how you do it. (if you do)

Why not just manage it all with your own classes in one app state?

It’s ok to make your own classes. Not everything needs to be a control or an app state.

1 Like

i already have own entity system if you mean it. and yes, i also have there when add or remove spatial. but it base on different distance factor. could do it there too.

But i feel like its more “universal” to just attach control and it just work. to anything, it dont even need to be entity.

Yes, but controls may be attached to a spatial in 100 different viewports. So “I need a control that uninitializes X, Y, Z when detached.” is a use-case waaaaay outside of the use of controls. And the one thing the calling code definitely knows is when it is attaching and detaching that control/spatial… and thus can do its own cleanup when detaching spatials. For JME, this is “unknowable”.

But maybe I misunderstand the question.

1 Like

Maybe take a step back and describe the actual effect you are trying to achieve without regard to the specifics about how you’ve done it already.

1 Like

Maybe take a step back and describe the actual effect you are trying to achieve without regard to the specifics about how you’ve done it already.

nothing special, just wanted to make physics and lights LOD system(with more factors than just distance) without use of entity system. something like terrain.addControl(LOD)

Where in this case detail mean for example how many lights/ what type of light/ etc. show - for lights

So lets say i got characier in distant area, it is attatched, but i want to see this light when its little closer.

so i thought i will make universal control that will manage it. and i did, but approach is ugly since control dont call anything when its spatial is detached from renderNode (rootNode)