Probably at some point, the struct is returned as value, creating a copy
I’m indirectly getting reference to USTRUCT()
FGAAttributeBase& UGAAttributesBase::GetAttribute(const FGAAttribute& Name)
{
UStructProperty* tempStruct = FindField<UStructProperty>(this->GetClass(), Name.AttributeName);
FGAAttributeBase* attr = nullptr;
if (tempStruct)
{
attr = tempStruct->ContainerPtrToValuePtr<FGAAttributeBase>(this);
return *attr;
}
return *attr;
}
And then I try to set value to it like that:
FGAAttributeBase& attr = this->DefaultAttributes->GetAttribute(eval.Attribute);
attr.AddBonus(FGAModifier(eval.Mod, eval.Value), HandleIn);
And now when inspecting in VS attr have value changed.
But when inspecting DefaultAttribute (from which I got reference to this struct), the value of it is not updated.
What I’m doing wrong ?
Edit:
For the testing purposes I also tried version with pointers:
FGAAttributeBase* UGAAttributesBase::GetAttribute(const FGAAttribute& Name)
{
UStructProperty* tempStruct = FindField<UStructProperty>(this->GetClass(), Name.AttributeName);
FGAAttributeBase* attr = nullptr;
if (tempStruct)
{
attr = tempStruct->ContainerPtrToValuePtr<FGAAttributeBase>(this);
return attr;
}
return attr;
}
FGAAttributeBase* attr = this->DefaultAttributes->GetAttribute(eval.Attribute);
float newValue = 0;
if (attr)
{
if (HandleIn.IsValid())
{
attr->AddBonus(FGAModifier(eval.Mod, eval.Value), HandleIn);
//DefaultAttributes->SetAttribute(eval.Attribute, attr);
}
}
But it’s exactly the same. It doesn’t actually set value inside struct within object from which I got pointer.