# BeginDestroy is never called?

**URL:** <https://forums.unrealengine.com/t/begindestroy-is-never-called/373940>\
**Category:** World Creation\
**Tags:** Destroy, actor, unreal-engine, Physics, question\
**Created:** [October 20, 2016, 5:21pm UTC](https://forums.unrealengine.com/t/begindestroy-is-never-called/373940 "2016-10-20T17:21:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [October 20, 2016, 5:21pm UTC](https://forums.unrealengine.com/t/begindestroy-is-never-called/373940/1 "2016-10-20T17:21:30Z")

</div>

// header  
virtual void BeginDestroy() override;

```
// cpp
void ABaseSegment::BeginDestroy()
{
	// Also destroy any obstacles that this segment may have spawned.
	for (int i=0; i<Obstacles.Num(); i++) // never called
	{
		Obstacles[i]->Destroy();
	}

	Super::BeginDestroy(); // outcommenting this line does not cause a crash for some odd reason even though it should.
}

```

Setting a breakpoint on the internal code will cause a crash:

```
void AActor::BeginDestroy()
{
	UnregisterAllComponents(); // <<<<< Setting breakpoint here will cause a crash where it complains about a super not being called. Works fine without a breakpoint. It seems that breakpoints are not allowed here.
	Super::BeginDestroy();
}

```

So I don’t really know how to debug this. Why is BeginDestroy() never called when I call Destroy() on the actor?

---

<div class="post-metadata">

**Author:** ![Gabriel\_Garcia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gabriel\_Garcia](https://forums.unrealengine.com/u/Gabriel_Garcia)\
**Post date:** [March 17, 2017, 8:07pm UTC](https://forums.unrealengine.com/t/begindestroy-is-never-called/373940/2 "2017-03-17T20:07:56Z")

</div>

I tried to use this too, also crashed, looks like on BeginDestroy all the actor references and components and whatsoever is already freed and can’t be accessed, I just swaped BeginDestroy with Destroyed and it worked.

```
//header
virtual void Destroyed() override;

//cpp
void AProjectile::Destroyed()
{
	Super::Destroyed();

	FVector location = GetActorLocation();
	DrawDebugLine(GetWorld(), lastPosition, location, GetColorByVelocity(), false, 15.f, 0, 3);
}
```

---

<div class="post-metadata">

**Author:** ![straypet](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@straypet](https://forums.unrealengine.com/u/straypet)\
**Post date:** [August 21, 2017, 5:14pm UTC](https://forums.unrealengine.com/t/begindestroy-is-never-called/373940/3 "2017-08-21T17:14:02Z")

</div>

You probably have moved on from this but I’m leaving the answer here in case anyone else comes upon the question.

BeginDestroy is not called as soon as an actor is destroyed. It will be called on the next Garbage Collector iteration.  
What does called immediately is “EndPlay”.

Here’s a handy AActor lifecycle guide:

> **[Actor Lifecycle](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Actors/ActorLifecycle/)**
>
> What actually happens when an Actor is loaded or spawned, and eventually dies.

---

<div class="post-metadata">

**Author:** ![FunGames55](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fungames55/32/710746_2.png) [@FunGames55](https://forums.unrealengine.com/u/FunGames55)\
**Post date:** [November 26, 2021, 7:16am UTC](https://forums.unrealengine.com/t/begindestroy-is-never-called/373940/4 "2021-11-26T07:16:36Z")

</div>

It seems like EndPlay is a superset of Destroyed and gets invoked in additional circumstances per the enum value other than being explicitly “Destroyed”. Depending on what needs to be cleaned up this may or may not be what you want, but based on OP it looks like they wanted to override “Destroyed” rather than “BeginDestroy”.
