FindPropertyByName: how to Cast UProperty to variable?

I’m checking if that class have specific variable using this approach:

GetClass()->FindPropertyByName(“DialogueTree”)

This is must be a variable of UBehaviorTree type. But this function above return UProterty type of variable. How can I convert it to UBehaviorTree?

Try

Cast<UBehaviorTree>(GetClass()->FindPropertyByName("DialogueTree"))

What are you trying to do? This sounds like a job for an interface or a component.

Getting an actual struct you can work with out of a UProperty is a colossal pain in the ■■■.

UProperty for varable is what UClass is for class, which means it’s property identifier in reflection system not variable itself as UClass is class identifier not a object of class.

each property type has it’s own UProperty implementation so first you need to cast to that type and then you can get value of that property from object pointer

UMyClassIWantGetValueFrom* Object = Somethingsomething();
UObjectProperty* ObjectProperty = Cast<UObjectProperty>(GetClass()->FindPropertyByName("DialogueTree"));
UBehaviorTree* Tree = Cast<UBehaviorTree>(ObjectProperty->GetObjectPropertyValue(Object));

if GetObjectPropertyValue wont work try GetObjectPropertyValue_InContainer with 0 on 2nd argument

Each UProperty will have diffrent get and set function, UProperty also have universal functions with void pointers which you can cast to any type

https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UProperty/index.html

The tree there is incomplete there is more UProperty types which you can find here: