Overriding object:removeSelf() and Groups

Hi everyone,

This post links slightly to another question I posted but think many of you might like it answered separately.
 

I’ve got a display group holding some display objects which are created using a separate module. When moving to a new scene using storyboard, this group gets removed in the default garbage clean up. Which all works perfectly fine.

However, the group’s children (display objects) don’t get removed using their own object:removeSelf() functions.

Can anyone advise on how to run a custom function [or even their own object:removeSelf() function] for each of the display objects before the parent group cleans them out? 

Thanks in advance,

Michael

Seems a bit messy in practice, but you could add each item to a table when they are inserted to the display group, then in the same area the scene change is performed, just above it run:

for i=1, #list, 1 do local item = list[i]; item:removeSelf(); item = nil; end

(NB: Nilling an item when you remove it also helps memory cleanup)

Seems a bit messy in practice, but you could add each item to a table when they are inserted to the display group, then in the same area the scene change is performed, just above it run:

for i=1, #list, 1 do local item = list[i]; item:removeSelf(); item = nil; end

(NB: Nilling an item when you remove it also helps memory cleanup)