# Modifying Struct Property changes a different Struct Property instead (C++ Editor Plugin)

**URL:** <https://forums.unrealengine.com/t/modifying-struct-property-changes-a-different-struct-property-instead-c-editor-plugin/739648>\
**Category:** C++\
**Tags:** unreal-engine, editor, question, CPP\
**Created:** [January 1, 2023, 1:34am UTC](https://forums.unrealengine.com/t/modifying-struct-property-changes-a-different-struct-property-instead-c-editor-plugin/739648 "2023-01-01T01:34:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![UsaidPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UsaidPro](https://forums.unrealengine.com/u/UsaidPro)\
**Post date:** [January 1, 2023, 1:34am UTC](https://forums.unrealengine.com/t/modifying-struct-property-changes-a-different-struct-property-instead-c-editor-plugin/739648/1 "2023-01-01T01:34:33Z")

</div>

Hello! I am trying to create an Editor plugin that creates several Light Actors and sets their LightColor property. Using [this Q&A answer](https://forums.unrealengine.com/t/set-get-uproperty-inside-of-ustruct-directly/315239/5) as reference, I created this code to get the `FStructProperty` representing the LightColor and set its properties. I want to just set the `R` property and leave the others.

```auto
// objectProp = Member struct property I want to modify. bp = Light Actor
if (const FStructProperty* colorValues = CastField<FStructProperty>(objectProp))
{
	if (const UScriptStruct* colorStruct = colorValues->Struct)
	{
		void* structSettingsAddr = objectProp->ContainerPtrToValuePtr<void>(bp);
		if (FProperty* colorProp = colorStruct->FindPropertyByName(FName("R")))
		{
			if (FByteProperty* colorByteProp = CastField<FByteProperty>(colorProp))
			{
				// Set only R value to 128 - Verified this is called using UE_LOG
				colorByteProp->SetPropertyValue(structSettingsAddr, 128);
				FEditPropertyChain EditChain;
				EditChain.AddHead(colorProp);
				EditChain.SetActiveMemberPropertyNode(objectProp);
				EditChain.SetActivePropertyNode(colorProp);
				FPropertyChangedEvent EditPropertyChangeEvent(colorProp, EPropertyChangeType::ValueSet);
				FPropertyChangedChainEvent EditChangeChainEvent(EditChain, EditPropertyChangeEvent);
				bp->PostEditChangeChainProperty(EditChangeChainEvent);
			}
		}
	}
}

```

What I expect is several Light Actors created with LightColor property having `R = 128` and `G = B = 255`. Instead, I get `R = G = 255` and `B = 128`! Here is a screenshot, this is the same for all Light Actors created:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/3/3e39281a954e1c2e8bfb605f858343dd0d9a83b8.png)

What is causing this? How can I prevent this issue?

---

<div class="post-metadata">

**Author:** ![UsaidPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UsaidPro](https://forums.unrealengine.com/u/UsaidPro)\
**Post date:** [January 1, 2023, 2:15am UTC](https://forums.unrealengine.com/t/modifying-struct-property-changes-a-different-struct-property-instead-c-editor-plugin/739648/2 "2023-01-01T02:15:51Z")

</div>

I think I figured out the cause for this. Looking at the UE source code, it appears that `SetPropertyValue()` actually just directly uses the address provided to it rather than manipulating the address to get the inner property address. Therefore, every call to `SetPropertyValue()` was setting the value _at the struct address_ which apparently = `B` for LinearColor property.  
Changing the logic to use `FColor* structSettingsAddr = objectProp->ContainerPtrToValuePtr<FColor>(bp);` solved the issue.
