Detect when an actor iis deleted inside the editor

Hello everyone,

Is there any way to know when an actor is deleted inside editor? The function Destroyed() doesn’t work inside editor and I assume the delegate for destroyed also doesn’t work.

Try BeginDestroy

Didn’t work for me…

I tried to print on log when BeginDestory is called. It didn’t work either.

What you have to do is hook a function up to an Editor Delgate.

First Include “UnrealED” in builds.cs:

if (Target.bBuildEditor)
{
PublicDependencyModuleNames.AddRange(new string] { “UnrealEd” });
}

Then include EditorEngine.h and use a #if WITH_EDITOR to make sure it is only included when in editor, necessary sicne you’re not allowed to package with editor code.

Then in OnConstruction hook up your delegate, you will have to add the functionOnActorsDeletedInEditor(AActor*) in .h as well.
I’m not sure why but i remember i didn’t work if i hooked up the delegate in Construct but worked in OnConstruction

#if WITH_EDITOR

#include “Editor/EditorEngine.h”

#endif

// Constructor
AVertexPaintDetectionTMapStorage::AVertexPaintDetectionTMapStorage() {

}

//----------------------------------------------------

void AVertexPaintDetectionTMapStorage::OnConstruction(const FTransform& Transform) {

Super::OnConstruction(Transform);

UE_LOG(LogTemp, Warning, TEXT(“TMap Storage On Construction”));

#if WITH_EDITOR

GEditor->OnLevelActorDeleted().AddUObject(this, &AVertexPaintDetectionTMapStorage::OnActorsDeletedInEditor);

#endif

}

//----------------------------------------------------

void AVertexPaintDetectionTMapStorage::OnActorsDeletedInEditor(AActor* deletedActor) {

// Executes everytime actor gets deleted in editor

}

1 Like