Code like this:
UUserWidget* UI= CreateWidget(GetWorld()->GetGameInstance(),UIClass);
Yes, you can set a widget’s owner to a GameInstance by using the GetGameInstance()
function instead of the GetWorld()->GetGameInstance()
function. Here’s an example:
UUserWidget* UI = CreateWidget(GetGameInstance(), UIClass);
By using GetGameInstance()
, you are getting a reference to the GameInstance that owns the current session (Project Settings), which can be used as the owner of the widget.