Read variable value from UProperty of different types

Hi.

I am trying to read the variable values from different blueprint components and while I was able to find how to do that for some variable types like float, double, bool and int I am not able to figure out how to do it for anything else. For example variables of type FVector, FRotator or any type of struct/enum/class. So how do I get the variable values for lets say a FVector, and do the other types work the same way?

I found that a FVector is a UStructProperty but I cant manage to access the vectors x, y, and z.

The following example is part of the code I have now where I successfully find bool and float values.

UCharacterMovementComponent *c = Cast<UCharacterMovementComponent>(Component);
if (c != NULL)
{
  for (TFieldIterator<UProperty> PropIt(c->GetClass()); PropIt; ++PropIt)
  {
    if (PropIt->IsA(UBoolProperty::StaticClass()))
    {
      UBoolProperty *BoolProp = CastChecked<UBoolProperty>(*PropIt);
      bool CurValue = BoolProp->GetPropertyValue_InContainer(c);
    }
    else if (PropIt->IsA(UFloatProperty::StaticClass()))
    {
      UFloatProperty *NumericProp = CastChecked<UFloatProperty>(*PropIt);
      float CurValue = NumericProp->GetPropertyValue_InContainer(c);
    }
    else if (PropIt->IsA(UStructProperty::StaticClass()))
    {
      UStructProperty *StructProp = CastChecked<UStructProperty>(*PropIt);
      // find values for FVector, FRotator, and so on
    }
  }
}

I should also point out that I will use this for a plugin so I have to find the properties from existing blueprints. So creating my own c++ class and use that when creating the blueprints is not an option.

Thanks in advance.

I solved it myself by using “UProperty::ContainerPtrToValuePtr”. I had tried it before posting this question but for some reason I could not get it to work on the first try. By using this I successfully read the values from all component properties.

Any chance you can share a little more code? I’ve been banging my head against the wall with trying to get/set FVector by variable name -_-

You could do it like this:

if (UIntProperty* IntProperty = Cast<UIntProperty>(Property))
{
    int32 Value = IntProperty->GetSignedIntPropertyValue(Property->ContainerPtrToValuePtr<int32>(Obj));
    SetIntProperty(Property->GetName(), Value);
}

but how to get properties values from UStructProperty?

Perhaps this answer can help: Set/Get UProperty inside of USTRUCT directly