TLDR: Is support for custom Creation Types planned in the UMG ViewModel Plugin?
I am very interested in the MVVM plugin currently in Beta. I’ve been exploring it a bit, and come across an issue I would love to solve.
When creating a ViewModel binding, you are prompted to use 1 of 4 Creation Types, which determine how a widget Fetches/Creates its ViewModel instance at runtime, which it then makes bindings on. I have noticed a few deficiencies in the 4 available options based on how I would like to use these ViewModels.
In my particular case, I would like to use the GlobalViewModelCollection, instantiating ViewModels from an external system and making them available to widgets at runtime. The problem here is that there is no guarantee that a ViewModel is made available before a widget is created. As the Widget (or more precisely, the widget extension named “View”), only seems to automatically try to fetch/create the ViewModel on “Construct”, using the GlobalViewModelCollection Creation type is insufficient.
Technically I could add a base widget class that can “retry” viewmodel Creation/Fetching if something goes wrong, but this is a dirty approach. There are other possible solutions as well, but all I can think of are similarly undesirable. I would much prefer a method to add custom Creation Types without modifying the engine Plugin itself.
With this goal in mind, I tried a cleaner, more native solution: reworking creation types entirely. To do this, I created a base UObject (let’s call it “UMVVMCreator”) marked “EditInlineNew”. This class had a single virtual function CreateViewModel. I then created subtypes of this UObject for each of the default CreationTypes, providing editable UPROPERTIES for only the data that the corresponding Creation Type needed. Finally, I replaced the Creation Type properties in the struct displayed in the ViewModel panel with a single Instanced uproperty of my UMVVMCreator.
In theory, this should have resulted in an EditInline dropdown for a creation type, where selecting the type will create an instance of the Creator object serialized in this UPROPERTY with the data customizable for that creation type directly in the panel. This would allow end users to create their own subtypes of UMVVMCreator, and they would immediately be accessible in the ViewModel panel for use. With a little bit more work, and exposing some extra functions on the “View” class, this could be used to create a “delayed” ViewModel Creation, where if it fails to fetch from the desired location, it can wait on a delegate notifying of when the correct ViewModel is created.
Unfortunately, this is where I ran into issues. Mainly, the EditInline property dropdown doesn’t work. It simply shows the available UObject types to create, and when one is selected, nothing happens (instead of populating the panel with that object’s editable properties). I imagine this may have something to do with the EditInline parameter not necessarily being in a UAsset, but instead some odd editor struct. My editor scripting knowledge is lacking, however. I was hoping this solution would work so I could submit a pull request and possibly get this added functionality into the engine.
So this leads me here. I would like developers to be able to provide Custom Creation Types to support extra functionality that the defaults do not provide, however I do not want them to be required to modify the engine plugin to do so.
Is this a feature that is in the pipeline? Has it even been discussed? Should my proposed EditInline solution be possible and is simply blocked by a bug with the ViewModel panel?