[UE 4.7.6 + Windows 8.1] PostEditChangeProperties is not called following basic tutorial

Hello!

I am following the tutorial Introduction to C++ Programming in UE4.

However, when I finish the portion “Extending a C++ Class via Blueprints”, the expected result simply doesn’t happen after changing the values on the Editor.

Here’s the code:

MyActor.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "CustomBaseDefense.h"
#include "MyActor.h"


// Sets default values
AMyActor::AMyActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	TotalDamage = 200;
	DamageTimeInSeconds = 1.f;
	UE_LOG(LogTemp, Warning, TEXT("AMyActor"));
}

void AMyActor::PostInitProperties()
{
	Super::PostInitProperties();

	CalculateValues();
	UE_LOG(LogTemp, Warning, TEXT("PostInitProperties"));
}

void AMyActor::CalculateValues()
{
	UE_LOG(LogTemp, Warning, TEXT("CalculateValues"));
	DamagePerSecond = TotalDamage / DamageTimeInSeconds;
}

#if WITH_EDITOR
void AMyActor::PostEditChangeProperties(FPropertyChangedEvent& PropertyChangedEvent)
{
	UE_LOG(LogTemp, Warning, TEXT("PostEditChangeProperties"));

	CalculateValues();

	Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

MyActor.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class CUSTOMBASEDEFENSE_API AMyActor : public AActor
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
	int32 TotalDamage;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
	float DamageTimeInSeconds;

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Damage")
	float DamagePerSecond;

	// Sets default values for this actor's properties
	AMyActor();

	// You can create default values based off of designer set values by hooking into the PostInitProperties() call chain. Here’s an example of that process where TotalDamage and DamageTimeInSeconds are designer specified values.
	void AMyActor::PostInitProperties();

	void AMyActor::CalculateValues();

	void AMyActor::PostEditChangeProperties(FPropertyChangedEvent& PropertyChangedEvent);

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	
	
};

I have even added some log messages to be sure the method wasn’t being called and here’s the log after changing the properties:

LogTemp:Warning: AMyActor
LogTemp:Warning: CalculateValues
LogTemp:Warning: PostInitProperties
LogTemp:Warning: AMyActor
LogTemp:Warning: CalculateValues
LogTemp:Warning: PostInitProperties
LogContentBrowser: Native class hierarchy updated for 'CustomBaseDefense' in 0.0040 seconds. Added 5 classes and 2 folders.
Warning: HotReload successful (1 functions remapped  0 scriptstructs remapped)
LogContentBrowser: Native class hierarchy populated in 0.0096 seconds. Added 1702 classes and 265 folders.

As you can see, there’s no “LogTemp:Warning: PostEditChangeProperties” on the log.

I’ve even tried removing the conditional “#if WITH_EDITOR” statement, but nothing changed and the same result occurred. Any ideas?

Thanks in advance!

Hi ScorchedPsyche,

The reason this function isn’t working as you expect is due to a simple error and it still took me a few minutes to notice it. You’re using the right function in the Super call, but not for the function itself. The function should be PostEditChangeProperty, not PostEditChangeProperties. Be sure to change it in both the .cpp and the .h. One way to avoid this in the future is to include override before the semicolon on the declaration. If you include override, it won’t let you compile if the function doesn’t exist in the parent class.

Have a nice day,

Matthew Clark