[MVVM] How to use "Context" CreationType properly ?

Hello, I’m trying to use the Context ViewModel CreationType on a child Widget Blueprint (WBP). But it never works the way I’d expect.

In short, when I try to use this type in a child WBP, the ViewModel doesn’t get set properly and I’m getting the following error :

Error Model View Viewmodel The new viewmodel MyViewModel cannot be evaluated again. WBP_ImpactedChildWBP

The use case is the following :

  • I have a WBP (let’s name it “WBP_Score”), reusable in multiple contexts.
    • This WBP expects a “ScoreViewModel” : I’m setting its creation type to Context
  • I put it as a child of another WBP (e.g. “WBP_PlayerCard”)
    • This WBP has a valid “ScoreViewModel”, set properly thanks to some Resolver

My guess is that the ViewModel on the parent WBP is set too late, and the Context CreationType on the child WBP doesn’t support re-evaluating the ViewModel afterwards.

Is this a known bug? Has any anyone managed to use this option properly ?

Hey there!

Working with viewmodels in a hierarchy of widgets can be a bit tricky.

  • What version of Unreal are you working with?

  • And are you connecting the Resolver on your parent widget (WBP_PlayerCard) with logic inside your blueprint graph or are you using the MVVM viewmodel view bindings panel?

From what you’re describing, your guess is spot on:

The Context creation type expects the viewmodel instance to already exist and be initialized higher up in the hierarchy by the time the child widget initializes.
When WBP_Score is instantiated as a child, it looks up the widget tree for that context too early before WBP_PlayerCard resolver has fully evaluated and assigned it, throwing that evaluation error because it tries to bind before the parent’s data context is live.

Let me know those extra details and we can figure out the cleanest way to structure your viewmodel

Hey! :slight_smile:

  • Unreal version : 5.8.1
  • No logic inside the Blueprint graph. The Resolver on the parent widget (WBP_PlayerCard) is connected through the Details tab when focusing on the ViewModel in the ViewModel tab. I have tried both using a dummy binding, or relying on the “Create View Without Bindings” option.

After some debugging, I can attest the behaviour you described. But after this debugging session, I have trouble understanding how the Context creation type could ever work: are there actual use cases where the ViewModel already exists upper in the hierarchy?

To work around the issue, I’m currently using the same Resolver on the child WBP. But this won’t scale if I want to re-use this particular WBP in other contexts.

Do you have another way in mind to structure my use case?

On a side note, as a user, I would have expected the Context creation type to use the newer ViewModel if it ever changes upper in the hierarchy or if the WBP is moved to another context. Also, the warning happens at the moment the newer ViewModel is set, so it doesn’t seem impossible to handle this case

Hey @midiphony-panda Thanks for the follow-up and additional info!
Great to know you’re using Unreal Engine 5.8.1 and that you’re setting up the parent resolver directly in the Viewmodel Details.

You are running into a core part of how the MVVM framework works.

Why Context will not work with Nested Widgets

When creating a Context using this type, it looks up in the UMG hierarchy to find a widget that already has an instance of this ViewModel class set.
However during the initialisation of the child widget, the parents ViewModel view bindings have not been completely resolved. As such when trying to evaluate the context of the child widget, the error will throw as The new viewmodel [ViewModel] cannot be evaluated again.

Context is primarily intended for cases where a ViewModel is guaranteed to exist higher up before the child is constructed.
For example, when a parent widget creates its ViewModel in PreConstruct/C++ or when assigned via an outer UI manager before the child’s initialization pass.

Alternative Ways to Structure Your Reusable Child Widget

To keep WBP_Score modular and reusable without hardcoding a specific Resolver inside it, here are the two cleanest patterns you could use

Option 1: Manual Creation Type with an Explicit Setter

Instead of relying on Context, let the parent widget pass down its ViewModel instance directly.

  1. Open WBP_Score and go to Window → Viewmodels

  2. Select your ScoreViewModel and change Creation Type to Manual.

  3. Check Create Setter Function in the Details panel

  4. In your parent widget (WBP_PlayerCard) when the parent ViewModel updates (or on Construct) call the generated Set Score View Model function on the WBP_Score child reference.

Why this could works: It decouples WBP_Score completely from how the ViewModel was created or resolved, making it 100% reusable anywhere in your project.

Option 2: Property Path Creation Type

If you want automatic binding without Blueprint graph code, you can route through a function or property.

  1. In WBP_Score set the Creation Type to Property Path

  2. Point the path to a function or property on your Outer/PlayerController/Parent (e.g, GetPlayerController.GetScoreViewModel)

Epic Documentation: UMG Viewmodel

Let me know if these options were helpful and if you have any other questions, don’t hesitate to ask!

Thanks for the workarounds. We will probably choose between those options on a case-by-case basis.

I still believe proper support for the Context creation type would be better from my user perspective :sweat_smile:

I’m marking your answer as the solution but still think it would be more maintanable to support this post-initialization thing with Context. I tried some changes in the engine’s MVVMView.cpp to support it and it works well, although it’s just a prototype.