I’m working on an idea to implement a plugin that would need to be able to read all UPROPERTY() declared members of a class. For example, I have a class names AActorTest, that is a child of AActor, with a simple member:
UPROPERTY()
int32 aSimpleInt = 0;
Is there a way to access all the UPROPERTY() properties in any way, like via the StaticClass? And then get the value of that variable for an instance of that class afterward?
I know this may sound weird, but for my plugin to work the intended way, I would need to do something like this. If anyone has any way to do this (or something similar), let me know!
Allright, this is exactly what I needed! I’m still digging around, I also found
UProperty* testValueProperty = FindField(GetClass(), “mTestValue”);
that is quite useful for what I want to do. I’m still reading about all this but you’ve been a great help! The reflection page you linked is really great too.
bool UShooterFunctions::GetFloatByName(UObject * Target, FName VarName, float &outFloat)
{
if (Target) //make sure Target was set in blueprints.
{
float FoundFloat;
UFloatProperty* FloatProp = FindField<UFloatProperty>(Target->GetClass(), VarName); // try to find float property in Target named VarName
if (FloatProp) //if we found variable
{
FoundFloat = FloatProp->GetPropertyValue_InContainer(Target); // get the value from FloatProp
outFloat = FoundFloat; // return float
return true; // we can return
}
}
return false; // we haven't found variable return false
}
Do you guys know if this works the same way if I want to get an actor reference which is stored in a variable? So get the actor reference by the variable name essentially. I an actor reference also considered a property?