FPropertyChangedEvent - Mesh disappears, when editing value in Editor

Hello everyone,

I tried to create my own c++ Item class, by extending the AActor class, that has some specific behaviour, when I change a property in the editor. I implemented the FPropertyChangedEvent and everything worked out well, but each time I changed the value of a boolean - I only had boolean variables - the StaticMesh that was also attached to the Item disappeared in editor. (Later I tested it with other variables like int32 and it also happened.)

On play the mesh is visible, but in the Editor it only gets visible again after relaunching the engine.

(On A everything worked normally and after clicking on the boolean the Mesh disappeared as seen in B)

I reproduced the error on a simple example like this:

MyActor.h

UCLASS()
class EDIORCHANGETRY_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyActor(const FObjectInitializer& ObjectInitializer);

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

	// Called after variable was changed in Editor.
	virtual void PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent) override;
	
	//Boolean Test variable
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General")
		bool boolean;

	//Mesh attached to the root of the component
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mesh")
		UStaticMeshComponent* Mesh;

	//Arrowcomponent just as root component of the Object.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mesh")
		UArrowComponent* Arrow;
};

MyActor.cpp

// Sets default values
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
{
 	// 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;
	
	//Set default value of boolean.
	boolean = false;

	//Set default subobject of Mesh.
	Mesh = ObjectInitializer.CreateDefaultSubobject < UStaticMeshComponent > (this, TEXT("Mesh"));

	//Set default subobject of Arrow.
	Arrow = ObjectInitializer.CreateDefaultSubobject<UArrowComponent>(this, TEXT("Arrow"));

	//Set arrow as root.
	RootComponent = Arrow;

	//Attach mesh to root component.
	Mesh->AttachTo(RootComponent);
}

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

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

// Called after variable was changed in Editor.
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent)
{
	//There isn't even code in here.
}

Am I missing something here or is this a bug?

Greetings,
Ukmasmu

1 Like

Hi Ukmasmu,

When you override a function from the parent class, as you are doing in this situation with PostEditChangeProperty, you have to include a Super to call the original function that you’re overriding. You would need to add this to the body of the function:

Super::PostEditChangeProperty(PropertyChangedEvent);

After doing this and compiling, changing things in the editor will no longer make them disappear, but it will allow them to update on the fly.

Have a nice day,

Yeah, that was it. :smiley:

Thanks.

Glad to hear it. Let us know if you need any more assistance.