This might sound similar to topics that have been brought up before, but I am trying to handle this from a Control so I don’t have to be specific when I want lights removed.
For this example, say I’ve got a lantern in the room, it’s physical (doesn’t matter too much). The light’s position is updated by a LightControl, and my spawner’s code gets that light added to the Root Node without issue.
But, if I were to detach the lantern, there would still be a light to deal with. On a specific case, I could tell that it was a lantern, maybe even extend a custom Control that referenced the Root Node that my removal code could trigger to cleanup.
Now, say I have a LightNode in place so I can adjust the light’s relative position. Now the lantern lacks any indication it needs cleaning up. If that lantern was attached to another node, that’s another step removed.
I thought maybe I could create a custom Control extending LightControl that holds the node the light gets assigned to (Root Node, but it could be different)
There are a few snags to this plan:
- A Control wouldn’t get updated after its Spatial was detached.
- I could make a custom Node (I’d call it ‘DethNode’) that could “announce” certain Controls (and other DethNode children) of their impending demise. But if it was the child of a normal Node, I’m back in the same boat for nothing.
- A Control I’ll call “DethControl” or maybe “EventControl” that my removing code can spot and pass a “detaching” message to pass down through. (It would check if the Spatial were a node, then if it had children, and if any of those children had an EventControl and pass the signal). On adding, it could even attempt to propagate upward and add an EventControl until it was just shy of the Root Node (or just hit the Root Node, it wouldn’t matter).
The “DethControl/EventControl” idea could probably work and I could implement it that way, but it feels messy to just have a string of Controls that just exist to pass a signal. Any more experienced hands have a cleaner way to tell when an ancestor’s been detached? Like a listener or something?
I was planning to use some implementation of this concept to clean up light sources, remove references from my scripting engine, or maybe announce a removal to a queue I could set up during my spawning step.