As of 5.0.3 (and probably before, maybe 5.0?), CreateWidget
works with any of the following owning objects:
UWidget
UWidgetTree
APlayerController
UGameInstance
UWorld
So, since UMainMenu
is a UWidget
, it’s ok to just pass this
.
–
Given the error message in the instructor build output, I suspect that, at the time of the recording, CreateWidget
was a regular function (or 3 of them, one of each owning object type). With 5.0.3, it’s a template that does a compile-time check:
template <typename WidgetT = UUserWidget, typename OwnerT = UObject>
WidgetT* CreateWidget(OwnerT* OwningObject, TSubclassOf<UUserWidget> UserWidgetClass = WidgetT::StaticClass(), FName WidgetName = NAME_None)
{
[...]
static_assert(TIsDerivedFrom<OwnerT, UWidget>::IsDerived
|| TIsDerivedFrom<OwnerT, UWidgetTree>::IsDerived
|| TIsDerivedFrom<OwnerT, APlayerController>::IsDerived
|| TIsDerivedFrom<OwnerT, UGameInstance>::IsDerived
|| TIsDerivedFrom<OwnerT, UWorld>::IsDerived, "The given OwningObject is not of a supported type for use with CreateWidget.");
[...]
}