MVVM C++ inconsistencies and documentation issues (UE 5.2)

Hi,

I have a few issues with the new MVVM Plugin. Over all I like the approach, but there are some issues I have/had when experimenting with it:

First I think there is an inconsistency in the documentation. It states

When you define variables in your Viewmodel, each variable should be Private, and must have a UPROPERTY macro with the FieldNotify specifier

However further down the documentation page, the code sample shows all properties to be public. This should be corrected or clarified, or redesigned? See below:

The second issue is that the Viewmodel’s properties used in view binding must indeed be public (at least from what I tried) to be usable in the View Binding editor in a widget blueprint. So the documentation should be clear about that.
However, I think this its not good, from a design perspective, to expose the properties directly as public members anyway. An unaware programmer may directly modify the public properties (via C++ or BP code), which would not be reflected in the widgets using the Viewmodel, because of the missing UE_MVVM_SET_PROPERTY_VALUE macro invocations.

So my proposition would be to modify the FieldNotify backend code in such a way that the properties can be private, and still can be accessible in Blueprint/View Binding Editor code. Either trough accessor functions or directly. Whatever better fits UE’s design philosophy.

If this is not the correct channel to post this, it would be nice if you could point me to the right direction :slight_smile:

Cheers

3 Likes

Don`t forget that MVVM plugin is in Beta state as for now.

You can declare your ViewModel variable as protected (or use AllowPrivateAccess specifier to make it private) with BlueprintReadWrite, so you can use ViewModel bindings and restrict access to it in C++ code