Object creation and garbage collection is a time consuming task. Reserving and freeing memory all over the place also causes memory fragmentation, which is something you want to prevent. WidgetBox is a Object Pool specific for widgets which will keep removed widgets in a pool for reuse.
WidgetBox is the smart way of handling that issue. The WidgetBox will create widgets for you as needed but will save them for reuse when the widgets got removed from parent. It’s useage is very simple (See NoGo section below for what you should NOT do) and keeps the code slick.
As I’m not able to set a hook in the engine when the widget is added to a parent, there is a restriction that you must take into account. NEVER EVER ADD a widget from the WidgetBox **TWICE **after getting it from the Box.
Go Green - Widget Recycling
The WidgetBox will only create new widgets if there is no free widget of the specified class. To make a widget available again, remove it from the parent. The widget will go to the Box itself to be marked available again.
To use a widget with WidgetBox, it must inherit from WidgetBoxWidget.
-Very simple setup and usage
-New widget only get created when pool is empty
-Removing a WidgetBoxWidget from parent places it back into the box.
-Multiple Box instances if needed
-One Box, All classes you want (inheriting from WidgetBoxWidget)
-The power of C++
How to set it up?
1: Download and place the contents into '…/MyGame/Plugins
2: Restart Editor
3: Enable Plugin in Edit->Plugins
4: Restart Editor
Feature Request & Bugs
Let me know.