Developer Notes

UOBject lifetimes are governed by a garbage collection system. "Destroyed" doesn't mean the c++ object goes away, it is instead deleted when a garbage collection pass is ran

Description

Functions called in the destructor are not being called properly. Setting a call to AddOnScreenDebugMessage is displayed at the start of PIE rather than when the actor's destroy is called.

Steps to Reproduce

1. Open UE4Editor (any project)
2. Add code to project based on Actor (MyActor)
3. Add destructor fuction to MyActor.h (~MyActor(); )
4. Add destrcutor implementation to MyActor.cpp

AMyActor::~AMyActor()
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Actor destroyed"));
	}
	UE_LOG(LogTemp, Log, TEXT("Actor has been deleted"));
}

5. Compile
6. create blueprint based on class
7. Wire keypress T event to a Destroy Actor call
8. Set Default Receive Input to Player 0
9. Play in Editor and press the T key

Result:
"Actor Destroyed" is displayed at the beginning of PIE rather than when the call to Destroy Actor is made. Also output log does not display message until after PIE is exited

Expected:
Actor exists until T is pressed. When Destroy Actor BP node is triggered it calls the code based destructor function to execute function calls inside at that time.

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

0
Login to Vote

By Design
ComponentUE - Gameplay - Blueprint
Affects Versions4.8.1
Target Fix4.9
CreatedJul 13, 2015
ResolvedJul 13, 2015
UpdatedApr 27, 2018