I’m in a dilemma creating a UI and need to rethink my design.
When accessing a subwidget’s functions from outside, i have to jump through many layers.
Therefore, I am wondering whether I should consolidate the processing into one master widget to avoid this, or write the processing in the sub-widget and execute it, or process it in the PlayerController that holds the UI.
This process does not refer to displaying a UI, but rather to processing that affects the save data and the actors involved.
I have been writing processing in sub-widgets, but as the number of them increased it became very confusing and the data and UI display became uncoordinated.
In short, should the UI process the data or simply display it?
This is a hard question and the right answer is “It depends.”
I’ve worked on projects with a “Master Widget” but unless you can make all your logic very very simple and all contained within the master it starts to become a monstrosity where it’s hard to find anything.
I prefer working with self contained widget-object pairs. Each widget manipulates directly and displays information about (preferably) one object or container and as long as it has the object provided it can be added and removed at will from the viewport. Other widgets might include it but they will only give it an object to manipulate and forget about it. The “processing” part should be in the widget if it is purely visual (like ordering items by price) or is in the object if it has game-play implications (selling items for example). If it becomes too bloated - make a function library with functions that processes your data, filter, sort, etc. and use those instead.
To be honest it really depends on the volume and nature of the processing but most important is what is more convenient for you.
Keep in mind that the whole viewport (and UI) does NOT exist on a dedicated server (or for AI controllers) so whatever logic you have in a widget be sure to be purely visual.
Maybe you can decouple the viewports with viewmodels.
and have an AHUB class be the coordinator of which ui to show with a widget switcher.
This video is also has some ok logic:
I didn’t know about viewmodels. This seems really useful.
Thank you for this information.
Also thanks for the idea of self contained widget-object pairs.
This was a method I had never thought of before.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.