What's the more cost efficient way of dealing with widgets.

I have a widget that only activates at certain points during the gameplay. I’m wondering what’s more efficient:

  1. Create and add the widget to viewport in a collapsed state once the level starts, then set visibility to visible when activated, and back to collapse when inactived.

  2. Add or remove the widget from viewport when needed.

Add it to the viewport once and then set it Hidden / Visible it, don’t Collapse it. You’d collapse it if its geometry was supposed to affect something else, like a slot in a vertical box. Is it supposed to?

Also, if this is a single widget, whichever method was chosen, it would have no measurable impact on performance whatsoever; that’s unless the widget is crazy complicated or loads stuff, which it should not (unless it must, ofc). Or if we’re talking about hundreds of instances created simultaneously.

Adding to viewport triggers the Construct event which (apart from potential performance hit when you create hundreds) may reset the widget if you relied on the event to make the widget in the first place.

3 Likes