Announcement

Collapse
No announcement yet.

How do i get/set var from PropertyChangedEvent?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do i get/set var from PropertyChangedEvent?

    My code is crushing engine
    Code:
    #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
    Last edited by Repin Design; 11-13-2017, 10:25 AM.

    #2
    You probably have an infinite loop due to this:

    Code:
     
     ChangedProperty->SetPropertyValue_InContainer(ChangedProperty, AttributeMinimalValue);
    Which is probably calling
    Code:
       
     PostEditChangeProperty
    again, which is calling SetProperty, which is calling postedit, which is

    So you should not be setting property value in posteditchange


    Have you tried using

    Code:
    virtual void PreEditChange(UProperty* PropertyThatWillChange) override;
    instead?

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



    Rama
    UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

    ♥ Rama

    Comment


      #3
      Originally posted by Rama View Post
      You probably have an infinite loop due to this:

      Code:
      ChangedProperty->SetPropertyValue_InContainer(ChangedProperty, AttributeMinimalValue);
      Which is probably calling
      Code:
      PostEditChangeProperty
      again, which is calling SetProperty, which is calling postedit, which is

      So you should not be setting property value in posteditchange


      Have you tried using

      Code:
      virtual void PreEditChange(UProperty* PropertyThatWillChange) override;
      instead?

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



      Rama
      I got the same result by some reason ;( my head is about to exlode.
      Last edited by Repin Design; 11-16-2017, 07:06 PM.

      Comment


        #4
        should i use "this" as object reference when i set it up?

        Comment


          #5
          Code:
          float ChangedPropertyValue = ChangedProperty->GetPropertyValue_InContainer(ChangedProperty);
          If you crash may be because ChangedProperty is nullptr (cast failed).
          | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

          Comment

          Working...
          X