The Unreal documentation does not provide any information about the “Resolver” initialization method for ViewModels.
-
Are there any good resources for learning about when and how this initialization method is used and what specific use cases or advantages the method provides?
-
Would it be possible to get an example of how the Resolver method is initialized and the setup required if assigned to a widget? (i.e. we’ve seen some mention that it acts as a more simplified version of the “Global Collections” method which still requires an identifier, do “Resolvers” require something similar)
[Attachment Removed]
Hi,
Good point about the docs, I believe resolvers were added a bit after the initial publication so it looks like we never updated them. We use resolvers quite a bit internally, they could be seen as a way to do more “scoped” collections but resolvers essentially let you fetch the VM through blueprints while being decoupled from an individual widget class. This makes it easy to share the “fetch the VM” logic with any widget class that might need access to a given VM. You can also add properties to the resolver and they’ll be exposed in the Viewmodel panel of the widget using that resolver, so you can pass forward parameters and let the resolver decide which VM to return.
For a practical example, imagine you have four players with their own health values, and the underlying data is stored on an instance of a PlayerStats viewmodel that is part of the player’s Pawn. You could then create a healthbar widget with a resolver that exposes player index as a parameter. In the widget, you specify the resolver and the index; the resolver then handles fetching that player’s Pawn and returning the appropriate viewmodel. This avoids tight coupling between the Widget and the Pawn, while also letting multiple different widgets use the same resolver to access that viewmodel and display the player health in different ways.
[Image Removed]A potential downside is that it can be hard to predict when the resolver will run, as it’s going to be tied to the creation of the widget. If a bit of UI containing a player healthbar was created before the player pawn had been spawned, the resolver would fail and you wouldn’t have a valid VM. A workaround there could be to have the resolver check if the pawn exists and add the widget to some deferred list if not (while returning some placeholder VM), then try manually assigning the viewmodel once that data actually exists.
Hopefully that example wasn’t too contrived, I’ll flag this with the docs team to see if we can get the docs updated to mention resolvers!
Best,
Cody
[Attachment Removed]