How do I execute a function when a variable is edited?

As an example

Camera zoom speed is an instance editable variable, so it might be changed at runtime in the editor, when that happens i need this function that sets the timeline length to run again since now that it’s been changed it would be out of date.

How would I do that?

Update the Timeline if the preCameraZoomSpeed variable differs on each tick.

That’s the basic hamfisted way of doing it yeah, I was hoping there might be a more elegant approach to doing it, I was hoping the construction script would do it but that one only runs when you trigger a function from the editor, not when you edit a variable

Then… override PostEditChangeProperty() in C++

virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override
{
    Super::PostEditChangeProperty(PropertyChangedEvent);

    if (PropertyChangedEvent.Property != nullptr)
    {
        FName PropertyName = PropertyChangedEvent.Property->GetFName();

        if (PropertyName == GET_MEMBER_NAME_CHECKED(AMyActor, CameraZoomSpeed))
        {
            OnValueChanged();
        }
    }
}
1 Like