How do I use the view model to preview real data on widgets during editor time?

Hello! I’m trying to set up a widget using a view model contract, and I’m running into issues previewing the data at editor time. In particular, whenever I try to set or query data on the view model during editor-time I get warnings that it’s null.

I first set my Viewmodel creation type to Create Instance with Create Setter Function, then I tried to create an instance of my view model in my widget in my preconstruct before I use it, but I just got more warnings saying that the object is null when I create it.


Next I tried unchecking Create Setter Function, then binding on construct to load the preview data when it’s changed. But when I loaded the preview using the preview button (which I only figured out how to enable thanks to this answer) and changed the preview data, I got the same warnings that the view model was null.

I know it must be possible to use the view model during editor time because the demo video for this feature does this! He even exclaims “no need to PIE!” So what am I doing wrong? How do I preview a widget with a view model without PIE?

I dug in a bit more closely and made a few key discoveries:

  • The construct node actually creates a valid view model object, but setting the view model fails!
  • This means the outer being self doesn’t seem to be an issue.
  • Setting fails both with this set node, and if you use the special setter function that’s made available when you check the Create Setter Function box on the details viewmodel

My hypothesis is that setting the view model somehow disabled at the time preconstruct is called for the “Create Instance” method. I haven’t been able to find the source code for the set function to verify this, but I’m also doing more digging. In order to also troubleshoot this to test my hypothesis, I plan on trying out the “Manual” creation method.