# Getting properties of a struct using FProperty

**URL:** <https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207>\
**Category:** C++\
**Tags:** unreal-engine, UE4-27, question, CPP\
**Created:** [May 30, 2022, 7:02pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207 "2022-05-30T19:02:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Boon](https://forums.unrealengine.com/u/Boon)\
**Post date:** [May 30, 2022, 7:02pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/1 "2022-05-30T19:02:14Z")

</div>

I have a case where I want to access the fields of a struct within a class using only the name of the field as an FName. I don’t know the type of struct, but I know it will always be called MyStruct. Target is a UObject\*. MyPropName is the name of the property within the struct.

```auto
FProperty* Struct = Target->GetClass()->FindPropertyByName(FName("MyStruct"));
FProperty* Property = Struct->GetClass()->FindPropertyByName(MyPropName);

```

This doesn’t work, I’m including it to explain what I’m trying to achieve. I found [this thread](https://forums.unrealengine.com/t/reading-struct-attributes-in-c/471834/3) which seems to work but it requires that I know the type that MyStruct is.

The situation I have is that I have a kind of Buff system where I give it the name of a property, and the value I want it set to.

The properties that I want to buff are always located inside a member variable called MyStruct, but that struct can be of different types.

I’m approaching it this way because I like encapsulating properties within structs, and I use that to reset variables by keeping a copy of the default MyStruct and on resetting, set MyStruct to the default.

I managed to get stuff working without the MyStruct, where MyPropName was just a float variable on the class itself, but I’d really like to know if it’s possible to access:

MyClass-\>MyStruct.MyPropName given only FNames and no types for MyStruct.

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [May 30, 2022, 8:47pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/2 "2022-05-30T20:47:52Z")

</div>

Your (FProperty\* Struct) does not contain MyStruct values, it only contains information about the “MyStruct” property within Target class.

To get a pointer to your struct instance in memory you need to use ContainerPtrToValuePtr.

Then to get information about the properties within MyStruct, you need to access MyStruct reflection data. This is generally done via FMyStruct::StaticStruct or StaticStruct\<FMyStruct\>, however if you don’t know the type at compile-time you cannot use that here. Also as far as I know there is no GetClass() equivalent for structs.

Fortunately, that information is held in the struct property information, you can access it by casting to FStructProperty.

Here is a working example :

```cpp
template<typename T>
T* GetPropertyValueWithinStruct(UObject* Target, const FName& StructPropertyName, const FName& PropertyNameWithinStruct)
{
    // Get the reflected struct property
    FStructProperty* StructProp = (FStructProperty*)Target->GetClass()->FindPropertyByName(StructPropertyName);

    // Get a pointer to the struct instance
    void* StructPtr = StructProp->ContainerPtrToValuePtr<void>(Target);

    // Get the struct reflection data
    UScriptStruct* StructReflectionData = StructProp->Struct;

    // Get the reflected property within struct
    FProperty* PropertyWithinStruct = StructReflectionData->FindPropertyByName(PropertyNameWithinStruct);

    // Get value of property within struct
    return PropertyWithinStruct->ContainerPtrToValuePtr<T>(StructPtr);
}

```

Usage (assume MyField is an int32 property in MyStruct) :

```cpp
if (int32* ValuePtr = GetPropertyValueWithinStruct<int32>(this, "MyStruct", "MyField"))
{
    UE_LOG(LogTemp, Log, TEXT("Result: %i"), *ValuePtr);
}

```

---

<div class="post-metadata">

**Author:** ![JaredTherriault](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jaredtherriault/32/1194499_2.png) [@JaredTherriault](https://forums.unrealengine.com/u/JaredTherriault)\
**Post date:** [May 30, 2022, 9:01pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/3 "2022-05-30T21:01:22Z")

</div>

Check out ‘Engine\Plugins\VirtualProduction\LevelSnapshots\Source\LevelSnapshots\Private\Selection\PropertySelection.cpp’ at ‘FLevelSnapshotPropertyChain::FindPathToProperty’.

You’ll want to do something like:

```auto
FProperty* Struct = Target->GetClass()->FindPropertyByName(FName("MyStruct"));
	
if (const FStructProperty* StructProperty = CastField<FStructProperty>(Struct))
{	
    for (TFieldIterator<FProperty> It(StructProperty->Struct); It; ++It)
    {
         const FProperty* Property = *It;

        if (Property.GetFName() == MyPropName)
        {
	        // Here we have the property inside the struct
        }
    }
}

```

Then you can do what you were doing before where I assume you were casting single FProperty members to FFloatProperty or something then calling SetPropertyValue. The only difference is that you can’t use UObject as your container void\*, you’ll have to use the actual struct void\*.

```auto
void* StructPtr = StructProperty->ContainerPtrToValuePtr<void>(MyObject);

MyFloatProperty->SetPropertyValue(StructPtr, 1.0f);

```

---

<div class="post-metadata">

**Author:** ![Boon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Boon](https://forums.unrealengine.com/u/Boon)\
**Post date:** [May 30, 2022, 9:19pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/4 "2022-05-30T21:19:43Z")

</div>

This is exactly what I was after, thank you!

---

<div class="post-metadata">

**Author:** ![FISHJOANNA](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FISHJOANNA](https://forums.unrealengine.com/u/FISHJOANNA)\
**Post date:** [October 31, 2022, 8:16am UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/6 "2022-10-31T08:16:06Z")

</div>

Why PropertyName within USctripStruct is not exacetly the name we gived?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/7/5/7753c493da54c176ff489679f1f29567cc66bf52.jpeg)

---

<div class="post-metadata">

**Author:** ![JaredTherriault](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jaredtherriault/32/1194499_2.png) [@JaredTherriault](https://forums.unrealengine.com/u/JaredTherriault)\
**Post date:** [October 31, 2022, 6:26pm UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/7 "2022-10-31T18:26:12Z")

</div>

That’s the internal name. Each scriptstruct is basically another UObject and the name you see is not that of the struct, but the object that houses the struct data. If you want the name you wrote for the struct, use GetAuthoredName.

---

<div class="post-metadata">

**Author:** ![NODARYN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NODARYN](https://forums.unrealengine.com/u/NODARYN)\
**Post date:** [May 5, 2025, 3:16am UTC](https://forums.unrealengine.com/t/getting-properties-of-a-struct-using-fproperty/570207/8 "2025-05-05T03:16:54Z")

</div>

Look at this plugin:  
[https://www.fab.com/ru/listings/080230fd-914c-4c46-b764-46118b50a41d](https://www.fab.com/ru/listings/080230fd-914c-4c46-b764-46118b50a41d)
