Value of FProperty

Hello, I’m trying to pass values through a class of UObject to do so I passe the class then retreive each property but after that I don’t know how to get it’s value.

I can get its name and type but not its value.

FProperty* prop = LastSample->GetClass()->FindPropertyByName(FName(* fieldName));

This gets the Property and its full name matches.

1 Like

try this,

Value = prop->GetPropertyValue_InContainer(LastSample);

4 Likes

Thanks, it worked

That’s a function of TProperty how did you do it?

1 Like

@bierbrian It’s from FProperty, but you have to cast it. E.g. for a bool property you get the bool with:

if(Property->IsA(FBoolProperty::StaticClass())) {
  const FBoolProperty* BoolProperty = static_cast<FBoolProperty*>(Property);
  bool Value = BoolProperty - > GetPropertyValue_InContainer(Object);
  // ...
}

All core types like float, double, int, … have such a helper function to get the value.

3 Likes

I think you might be able to write:

if (const FBoolProperty* BoolProperty = CastField<FBoolProperty>(Property)) {

instead (which does the IsA and cast and checks for null in one move, like dynamic_cast) , but haven’t tested it sorry.

1 Like