How can I properly initialize TSoftClassPtr<>?

I’m trying to use TSoftClassPtr<> instead of TSubclassOf<> for a widget class reference, and when creating a widget, I tried using MyWidgetClass.Get() and MyWidgetClass.LoadSynchronous().

.Get() works in editor if I set the value of MyWidgetClass in the same session, but doesn’t work if I restart the engine.

.LoadSynchronous() works in editor even after I restart the engine.

However, neither works in a built project. So what do I need to do to make TSoftClassPtr<> work?

Thank you!

If there are only soft references to something, it will never get cooked into the game package. So for things like that, somewhere you need to have a reference to them, so they get packaged.

1 Like

Managed to replicate exactly this by checking if(!SftPtr.IsValid()) in case none was selected. It would always returns false unless I reassigned in the same session.

Works fine with if(!SftPtr.ToSoftObjectPath().IsValid()).

1 Like

I see. That’s good to know, thank you.