# Correct way to get the value of a Property?

**URL:** <https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897>\
**Category:** C++\
**Tags:** unreal-engine, Engine-Source-Code, UE4-26, CPP, question\
**Created:** [May 8, 2022, 11:45am UTC](https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897 "2022-05-08T11:45:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [May 8, 2022, 11:45am UTC](https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897/1 "2022-05-08T11:45:13Z")

</div>

Since the TProperty iterator uses a class as input, the Property still has to be pointed to an address to get its value from. Confusing design?

Question: How to get the value address properly, or how to directly iterate properties on an object instead of its class?

```auto
for (TFieldIterator<FObjectProperty> PropertyIterator(GetClass()); PropertyIterator; ++PropertyIterator) {
	FObjectProperty* Property = *PropertyIterator;
        UObject* PropertyValue = Property->GetPropertyValue(this);
}

```

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [May 8, 2022, 2:16pm UTC](https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897/2 "2022-05-08T14:16:04Z")

</div>

I suppose it could be confusing but it’s one of those cases where the API is built around the most utility and not necessarily around the easiest use. In your case you’ll want to look into the function `ContainerPtrToValuePtr`. That’ll give you the address.

```auto
void *ValueAddress = Property->ContainerPtrToValuePtr< void >( this );
UObject* PropertyValue = Property->GetObjectPropertyValue( ValueAddress );

```

I don’t see a version that does all that in one go, probably because the first call is part of the lower level property system and `Get` is part of `FObjectProperty`.

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [May 8, 2022, 2:58pm UTC](https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897/3 "2022-05-08T14:58:46Z")

</div>

Thanks, it works

---

<div class="post-metadata">

**Author:** ![rubm123](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rubm123/32/476292_2.png) [@rubm123](https://forums.unrealengine.com/u/rubm123)\
**Post date:** [November 10, 2022, 1:27am UTC](https://forums.unrealengine.com/t/correct-way-to-get-the-value-of-a-property/551897/4 "2022-11-10T01:27:13Z")

</div>

I am using this code to get the float value of a float property:

```auto
float NewVelocity = FFloatProperty::GetPropertyValue(SomeProperty->ContainerPtrToValuePtr<void>(this));

```

`SomeProperty` has type `FProperty`. `this` is the `UObject` that has the property “SomeProperty”. Note that `GetPropertyValue` is a static function. Replace `FFloatProperty` according to your property type.
