Reason for not using “Active Widget Index”

In answer to the locked topic: Why aren't we using "Active Widget Index"?

The reason to not use ActiveWidgetIndex in this situation is that, by specifying the exact widget to use in each situation, you’re making the code more intentional and less prone to error due to future changes. Imagine in the future, there are additional changes to the WBP_MainMenu, which adds an additional widget to the widget switcher at index 0, for whatever reason - maybe someone is adding a debug menu, or a new version of the main menu that they want to exist at the same time as the old main menu so that the two versions can be compared by a decision-maker, or whatever.

If this was done without checking the existing code, then the existing code would break, as changing to widget indexes “0” and “1” would now refer to the wrong menu widgets. However, if it’s done as in the video, even if additional widgets are added to the widget switcher and the indexes of MainMenu and JoinMenu change, the code functionality will still be preserved.

This is a good thing to keep in mind in projects with multiple team members, especially when there might be team members that are working entirely from within the editor, who wouldn’t think to, or feel comfortable to, check the backing code for a particular blueprint (as well as helping to catch yourself, if you forget that you’d set it up in that way a year ago). Ensuring that code is more resistant to unforeseen errors, and ensuring that if something breaks, it’ll break in a clear way (ideally with an error at compile time), is usually the ideal approach.

(I know this was from a couple of years ago, but might be helpful for future students)

1 Like

In the case of the indexes, first thing I did was define constants. Doesn’t solve the issue but does make it easier to move the around.

As for using a reference to a widget, this does have its own issues and could break compilation if removed or renamed. Of course, this could be desired as at least you know you did something bad.

Another solution might be to use references to widgets via properties which you attach the class references that you instance, one for each menu, and switch between them by removing one from the parent and adding the other.

Definitely food for thought anyway.

1 Like

Privacy & Terms