It's pretty hard to explain, but I will try my best. So, I have RenderComponent, EventManager and RenderSystem. In my RenderComponents constructor, I raise the renderComponentCreated event, which is signed by the RenderSystem. Using the args event object, I pass the RenderNode as data that contains the information that the renderSystem should draw the thing (popped, position and type).
So far so good. Now that the renderComponent has been removed, I want the RenderNode to be automatically removed from the RenderSystem, while maintaining the ability to manually delete it, for example. as a reaction to some event. This can be done using the RenderComponentRemoveNodeEvent, which again supports the RenderSystem.
Now the "problem". From my understanding (and from what I want), renderNode should be something unique owner of the RenderComponent (hence unique_ptr). However, this will require me to either copy (and implement the comparison operator for renderNode → to be able to find it when I want to delete it), or pass a reference / raw pointer to renderNode. However (if I'm right) there is no way to find out if the link refers to a valid object, which means that automatic deletion cannot be implemented.
My solution was to make a RenderNode (which uniquely belongs to the RenderComponent) and pass weak pointers to the event. RenderSystem also now maintains a list of weak pointers, which it checks to see if they all point to a valid object and automatically delete them if not. Therefore, in essence, I would like to create a weak pointer from the unique. However, as of now, someone can simply create a generic pointer from a weak pointer and save the RenderNode for longer than necessary. Since the managed object itself (RenderNode) contains references to other objects that will not last longer than the RenderComponent, this can cause serious problems.
My question now is: can this be considered a good design or am I missing something?
PS: , ( ) !