I need to monitor the change of a FName property. Implementing the PreEditChange() and PostEditChangeProperty() methods was easy enough but now I am stuck.
I cast the UProperty to UNameProperty but GetPropertyValue() or GetPropertyValue_InContainer() returns nothing useful.
This works for me:
void ACGALBox::PostEditChangeProperty(FPropertyChangedEvent& e) {
FName propertyName = (e.Property != nullptr) ? e.Property->GetFName() : NAME_None;
if (propertyName == GET_MEMBER_NAME_CHECKED(ACGALBox, meshWidth)) {
UFloatProperty* fp = static_cast<UFloatProperty*>(e.Property);
float* val = fp->GetPropertyValuePtr(&meshWidth);
UE_LOG(LogTemp, Warning, TEXT("%0.3f"), *val);
}
Super::PostEditChangeProperty(e);
}
Where my meshWidth
variable declaration looks like this:
private:
UPROPERTY(EditAnywhere, meta=(AllowPrivateAccess="true"))
float meshWidth;
And I set its default value in the constructor like this:
ACGALBox::ACGALBox() :
meshWidth(200.0f)
{
// Rest of ctor here.
}