How do I use PostEditChangeProperty?

Say I have a boolean UPROPERTY called MyBool. I want it so that when this is ticked true in the editor (details panel of my custom actor), a function will run to set some misc members of that actor.

PostEditChangeProperty() seems to be what I want, but I don’t get how to grab the value of the actual boolean. Here’s what I have so far:

void ASomeActor::PostEditChangeProperty(struct FPropertyChangedEvent& e)
{
	FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;
	if (PropertyName == GET_MEMBER_NAME_CHECKED(AInteractable, MyBool)) {
		UBoolProperty* prop = ???
		if (prop) doThings();
		else undoThings();
	}
	Super::PostEditChangeProperty(e);
}
1 Like

/* If MyBool belongs to the ASomeActor */
void ASomeActor::PostEditChangeProperty(struct FPropertyChangedEvent& e)
{
Super::PostEditChangeProperty(e);

     FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;
     if (PropertyName == GET_MEMBER_NAME_CHECKED(ASomeActor, MyBool)) {
             /* Because you are inside the class, you should see the value already changed */
                if (MyBool) doThings(); // This is how you access MyBool.
                 else undoThings();

            /* if you want to use bool property */
            UBoolProperty* prop = static_cast<UBoolProperty*>(e.Property);
           if (prop->GetPropertyValue())
               dothings()
          else
                 undothings()
     }
 }
4 Likes

Perfect, I should’ve realized that POSTEditProperty implied that it had already changed… Thanks!

Only to complete the great answer by @kishoreven, you can wrap the whole method inside WITH_EDITOR preprocessor definition:

#if WITH_EDITOR
void ASomeActor::PostEditChangeProperty(struct FPropertyChangedEvent& e)
{
    // ...
}
#endif
3 Likes

What if the property is located inside the code of a custom component on that actor, instead?

1 Like

If your component inherited from ActorComponent or SceneComponent, just override this in your Component Script.

You can find how I have used PostEditChangeProperty in my tutorial: Atari Pong Clone

1 Like