#MVC in Unity? I need advice (UI Toolkit)

1 messages · Page 1 of 1 (latest)

zinc rock
#

Hey. I've been trying to follow a MVC architecture in numerous drafts and failed projects with the UI Toolkit.

But currently I'm working on a more serious and big project, which is an editor tool that provides three Editor Windows, each with their corresponding UXML doc. The thing is, I tried to follow another MVC-like approach, and specially ListView elements are giving me headaches and diffusing the line between controller and view logic.

Could anyone with some experience with the UI Toolkit advise me?

#

MVC in Unity? I need advice (UI Toolkit)

granite linden
#

Why do you try to follow MVC when even .NET is no more using MVC in .NET Core

#

It is deprecated pattern

zinc rock
#

Using just EditorWindow–Model layers feels just too messy

#

Do you agree with me?

granite linden
#

As I understand you wanna use MVC for make good project structure. But you not need to separate whole project on Model View Controller. For some kind like action games you are not able to use View Controller the engine features won't let you to do it. You can create folder for scriptable objects, data base models (classes) so it will contain your assets it is okay. You can also use any patterns you want if you feel okay with that patterns.

zinc rock
granite linden
#

If you develop editor tool why do you want to use MVC you won't be able to go to another engine change View logic and get same result as you have in Unity it will not work such way.

#

Your core logic will be in unity specific EditorWindow behaviour

zinc rock
#

My intention using MVC was just to organize the project

#

To separate code in three different layers

granite linden
#

You already have to use Editor folder for EditorWIndow end else editor features, you have no need to worry about organization of project just do the logic that will work fine thats it

granite linden
#

You should worry about MVC only if you for example want to transfer whole logic to webpage in future or to another engine. You are welcome.

zinc rock
#

Any other advice is welcome and appreciated btw in case anyone else wants to comment anything

pastel hazel
glossy geyser
#

The biggest challenge in complex frontend is typically state management. For stuffs with simple state, you can practically do whatever and be fine. For more complex stuffs, I prefer using a reactivity system than hand wiring all these events and handlers.

#

(The code in the article above is way too enterprisey, with an interface for an implementation that is created from a factory. Realistically, it's only ever useful if you are actually going to have more than one implementation, and that in practice almost never happens with UI)

pastel hazel
#

it can be simplified however you wish, interfaces can be removed and all that
with a DI framework like VContainer or Zenject you can also reduce a lot of boilerplate around initialization

#

allows for easy unit testing, dependency mocking

#

I've been using some variation of this for a few years already, works great

glossy geyser
#

I have no doubt it does, MVC is tried and tested. The comment was aimed at the enterpriseness of the code, not the pattern.

#

In the web frontend world, state management has converged to signal based reactivity system. If you look at the MVC code in question, a property with a backing field where it triggers an event on set? That's just a signal, except written in 10 more lines than Signal<Vector3> Position.

#

There are source generator based solutions to cut down on the amount of boilerplate (eg MVVM Toolkit where you write only the backing field with an attribute and the SG generates the property and event for you) but personally I'm leaning towards these simply being a patch on patterns that lag behind the latest development in the field, which .NET frontend nowadays certainly feels that way to me.
Not that I'm saying stuffs like MVC/MVVM wouldn't work though.

valid dawn
zinc rock
#

I mean, not external, but also not default

valid dawn
near valley