Created
January 3, 2016 03:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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