How do I handle UMG ViewModels without crashing my game on quit?

#Summary
I’m working with the MVVM plugin:
UMG Viewmodel for Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

Q: When working with ViewModels that are hooked up to widgets, how do we handle lifecycle correctly?

#Bindings and Widget Lifecycle
A ViewModel (UMVVMViewModelBase) is created with the ViewModel pane, and has it’s properties hooked up via View Bindings to properties on the Sub-Widgets.

Do I need to implement, or override some sort of teardown?
Like an Uninitialize, Deinitialize or Destruct in the Widget? Or in the ViewModel? Or both?

#GlobalViewModels
So I can instantiate a view model, and store it inside a collection that lives in a World Subsystem via UMVVMGameSubsystem->GetViewModelCollection()

Do I need to be mindful of the lifespan of the World and it’s subsystems, versus the lifecycle of the widgets and UI that are on screen?

What’s some best practices here?

#XAML vs UMG gotchas
My background is in XAML based UI systems. WPF, UAP\UWP and Noesis.

I’m accustomed to magical strings in my declarative UI syntax, that doesn’t need any management for hooking up and tearing down elements. As long as the DataContext is set, it’s all good.

This being a game engine, and not software makes my assumptions invalid and risky.
So I think I need to be more careful about how to dismantle my UI.

1 Like