Skip to content

Instantly share code, notes, and snippets.

@nickdarnell
Created January 3, 2016 03:04
Show Gist options
  • Save nickdarnell/c01ed341f179bd73efb7 to your computer and use it in GitHub Desktop.
Save nickdarnell/c01ed341f179bd73efb7 to your computer and use it in GitHub Desktop.
Shows how to construct UUserWidget and modify it before it's fully initialized.
template< class T >
T* CreateWidget(UGameInstance* OwningGame, UClass* UserWidgetClass, TFunctionRef<void(T*)> PostNewModify)
{
UUserWidget* NewWidget = NewObject<UUserWidget>(OwningGame, UserWidgetClass);
if ( ULocalPlayer* Player = OwningGame->GetFirstGamePlayer() )
{
NewWidget->SetPlayerContext(FLocalPlayerContext(Player));
}
T* CastedNewWidget = CastChecked<T>(NewWidget);
PostNewModify(CastedNewWidget);
CastedNewWidget->Initialize();
return CastedNewWidget;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment