# Reading Struct Attributes in C++

**URL:** <https://forums.unrealengine.com/t/reading-struct-attributes-in-c/471834>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 27, 2020, 5:55am UTC](https://forums.unrealengine.com/t/reading-struct-attributes-in-c/471834 "2020-09-27T05:55:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [September 28, 2020, 9:21am UTC](https://forums.unrealengine.com/t/reading-struct-attributes-in-c/471834/3 "2020-09-28T09:21:39Z")

</div>

The following works for me :

```
// dummy test struct
FBlueprintCallableFunctionRedirect TestStruct;
TestStruct.ClassName = TEXT("Foobar");

// get the reflected property
FProperty* Prop = TestStruct.StaticStruct()->FindPropertyByName(FName(TEXT("ClassName")));

// Get value
FString Value = *Prop->ContainerPtrToValuePtr<FString>(&TestStruct);
UE_LOG(LogTemp, Warning, TEXT("%s"), *Value);

```

The pointer you are looking for is the instance of the struct object.

Here is a better example for your case, coming from a struct property in a UCLASS :

```
// header :
USTRUCT() struct FMyStruct {
    GENERATED_BODY()
    UPROPERTY() FString MyField;
}
UCLASS() class UMyObject : public UObject {
    GENERATED_BODY()
    UPROPERTY() FMyStruct MyStruct;
}

// cpp function :
MyStruct.MyField = TEXT("Foobar");

// get a pointer to the struct instance
FProperty* StructProp = StaticClass()->FindPropertyByName(FName(TEXT("MyStruct")));
void* StructPtr = StructProp->ContainerPtrToValuePtr<void>(this);

// get the reflected property
FProperty* StrProp = ((FMyStruct*)StructPtr)->StaticStruct()->FindPropertyByName(FName(TEXT("MyField")));

// get value in the struct
FString Value = *(StrProp->ContainerPtrToValuePtr<FString>(StructPtr));
UE_LOG(LogTemp, Warning, TEXT("%s"), *Value);
```

---

_[View the full topic](https://forums.unrealengine.com/t/reading-struct-attributes-in-c/471834)._
