# Set/Get UProperty inside of USTRUCT directly

**URL:** <https://forums.unrealengine.com/t/set-get-uproperty-inside-of-ustruct-directly/315239>\
**Category:** Editor Scripting\
**Tags:** UProperty, ustruct, unreal-engine, UE4, question, CPP\
**Created:** [April 16, 2015, 10:34am UTC](https://forums.unrealengine.com/t/set-get-uproperty-inside-of-ustruct-directly/315239 "2015-04-16T10:34:18Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![anonymous\_user\_10b75a231](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_10b75a231](https://forums.unrealengine.com/u/anonymous_user_10b75a231)\
**Post date:** [May 4, 2017, 2:10am UTC](https://forums.unrealengine.com/t/set-get-uproperty-inside-of-ustruct-directly/315239/5 "2017-05-04T02:10:14Z")

</div>

Structs are a little different than UObjects, but you can get and set their members like so:

```
float GetSetVectorX(UObject * ObjectWithVector)
{
	FName PropName = FName("MyVector");
	FName VectorMemberName = FName("X");
	float NewValue = 42.0;
	
	// Get property representing struct
	UProperty * Prop = ObjectWithVector->GetClass()->FindPropertyByName(PropName);
	
	// Ensure ObjectWithVector actually has a myVector member
	if (Prop)
	{
		// Get struct address
		void * StructAddress = Prop->ContainerPtrToValuePtr<void>(ObjectWithVector);
		
		// Ensure MyVector really is a vector
		if (UStructProperty * StructProp = Cast<UStructProperty>(Prop))
		{
			// We'll get struct properties through a UScriptStruct, not a UObject
			// ScriptStructs are just templates and don't hold any of your data
			UScriptStruct * ScriptStruct = StructProp->Struct;
			
			// Get the vector's "X" property
			UProperty * ChildProp = ScriptStruct->FindPropertyByName(VectorMemberName);

			// Cast to FloatProperty
			if (UFloatProperty * ChildFloatProp = Cast<UFloatProperty>(ChildProp))
			{
				// Get
				float OldValue = ChildFloatProp->GetFloatingPointPropertyValue(StructAddress);
				
				// Set
				ChildFloatProp->SetFloatingPointPropertyValue(StructAddress, NewValue);
				
				return OldValue;
			}
		}
	}
	return 0;
}

```

---

_[View the full topic](https://forums.unrealengine.com/t/set-get-uproperty-inside-of-ustruct-directly/315239)._
