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)
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”.