How do i get/set var from PropertyChangedEvent?

My code is crushing engine



#if WITH_EDITOR
void AUnitCharacteristics::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
   FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None;

   // Attribute Base Value Has Been Changed
   if ((PropertyName == GET_MEMBER_NAME_CHECKED(FUnitAttribute, BaseValue)))
   {
      UFloatProperty* ChangedProperty = Cast<UFloatProperty>(PropertyChangedEvent.Property);
      float ChangedPropertyValue = ChangedProperty->GetPropertyValue_InContainer(ChangedProperty);

      if (ChangedPropertyValue < AttributeMinimalValue)
      {
         ChangedProperty->SetPropertyValue_InContainer(ChangedProperty, AttributeMinimalValue);
      }
      CalculateTotalAttributes();
   }
   Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

You probably have an infinite loop due to this:


 
 ChangedProperty->SetPropertyValue_InContainer(ChangedProperty, AttributeMinimalValue); 

Which is probably calling


   
 PostEditChangeProperty  

again, which is calling SetProperty, which is calling postedit, which is :slight_smile:

So you should not be setting property value in posteditchange

Have you tried using



virtual void PreEditChange(UProperty* PropertyThatWillChange) override;


instead?

Cause that seems like what you want, to modify the change before it occurs

:heart:

Rama

I got the same result by some reason ;( my head is about to exlode.

should i use “this” as object reference when i set it up?



float ChangedPropertyValue = ChangedProperty->GetPropertyValue_InContainer(ChangedProperty);


If you crash may be because ChangedProperty is nullptr (cast failed).