Sharing another snippet of something I had to kinda of workaround.
I have a couple UIPanel widgets that I add as children to a grid. Upon closing the room I call a function to remove all widgets that are 'bound' to the room. Sadly panels that are parented to a Grid don't fully delete themselves. I had to use this workaround to get them to completely delete:
if (_widget.getType() == UI_TYPE.PANEL) { _widget.__parent.remove(_widget.getID()); UI.__destroy_widget(_widget); } _widget.destroy()
Full snippet for the logic to register and later remove widgets when the room ends:
global.widgets_to_remove = [] // Registers a widget that will be removed when the room ends function widget_bound_to_room(_widget) { array_push(global.widgets_to_remove, _widget) return _widget } // Called on room end to remove bound widgets function widgets_remove_room_bound() { for (var _i = array_length(global.widgets_to_remove) - 1; _i >= 0; _i--) { var _widget = array_pop(global.widgets_to_remove) custom_event_call("widget_removing_room_bound", { widget_to_remove: _widget }); // Workaround for panels not removing correctly if (_widget.getType() == UI_TYPE.PANEL) { _widget.__parent.remove(_widget.getID()); UI.__destroy_widget(_widget); } _widget.destroy() } }
To use it:
1. When creating widgets call widget_bound_to_room on it, e.g:
var _crafting_group = widget_bound_to_room(new UIGroup("CraftingGroup", 0, 0, 250, 0, spr_back, UI_RELATIVE_TO.MIDDLE_CENTER)) _crafting_group.setInheritHeight(true) _crafting_group.add(widget_bound_to_room(new UIPanel("ParentedPanel", _x, _y, _width, _height, spr_frame_simple)))
2. When the room ends call:
widgets_remove_room_bound();