Hello! I am trying to create an Editor plugin that creates several Light Actors and sets their LightColor property. Using this Q&A answer 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.
// 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:
What is causing this? How can I prevent this issue?