Home | Documentation | Atomic Chat | Github

Component Cleanup


I am adding some sprites to a node when a component is created. I was thinking I could remove those sprites in the remove method of the component, but it doesn’t actually get called.

What is the correct way to ‘cleanup’ inside a component when it is removed? I am thinking I will have to write my own “Remove” method and do the cleanup inside that.

What would be the correct way to remove a sprite from screen?

Hi Keith,

Node::Remove and Component::Remove are explicit calls, you use them to remove a Node from the Scene, or a Component from a Node, so you’re on the right path.

You wouldn’t add multiple sprite components to a Node generally, as these would all have the same transform. I would suggest creating Nodes with sprite components, and then when you are done with the nodes: mynode->Remove(); which will clean up both the Node and all the components on it in one easy call.

Creating nodes/components is pretty lightweight, though you may want to use Node/Component enable/disable functionality and pool if you have a lot of instances. It is also possible to remove/readd nodes to the scene graph, especially for simple components like sprites. YMMV when readding physics components for example.


Got it - thanks, Josh!