Getting variables by name?

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!

I feel like this as something to do with UProperty* and UField*, I’m still searching around but any help is appreciated!

Here you can see how you can iterate over all the properties: Unreal Property System (Reflection) - Unreal Engine

Quote:

for (TFieldIterator<UProperty> PropIt(GetClass()); PropIt; ++PropIt)
{
UProperty* Property = *PropIt;
// Do something with the property
}

You should be able to access the value using “UProperty::ContainerPtrToValuePtr” and “static TPropertyTypeFundamentals::GetPropertyValue

You can see an example in BlueprintNodeHelpers::CollectPropertyDescription

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.

Thanks again!

In case that tutorial goes away, the gist is:

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
}

Should be similar.

I should note that around 4.25 they renamed UFloatProperty to FFloatProperty.

There’s a UObjectProperty / FObjectProperty that may be what you need.

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?