I want to reference UMG widget class inside of c++ code, how can i get reference to it’s class and set it as Widget Class into Widget Component? Also how to cast to get variables and methods?
I believe this is similar to this question
To get a reference to a WBP Class, you can get it using :
ConstructorHelpers::FClassFinder<UUserWidget> WBPClassFinder(TEXT("/Path/To/WBP/WBP_Name"));
for example, I have a ServerRow Widget Blueprint in my project, in folder Content/Blueprints/UI, so I do :
ConstructorHelpers::FClassFinder<UUserWidget> ServerRowBPClass(TEXT("/Game/Blueprints/UI/WBP_ServerRow"));
then check if the blueprint was found and assign it to a TSubclassOf :
TSubclassOf<UUserWidget> WBPClass;
if (ServerRowBPClass.Class) ServerRowClass = ServerRowBPClass.Class;
To get the reference to a UCLASS, you can use ClassName::StaticClass() : UClass::StaticClass | Unreal Engine Documentation
To cast object from a class to another, you can use Cast(ObjectToCast) : Cast | Unreal Engine Documentation
Hope it can help ! I don’t know if it fully solves your question, if you need more informations tell me what else do you need
1 Like
Thank you very much, that’s exactly what i was looking for!