# ► React to Editor Destroying/Deleting an Actor

**URL:** <https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965>\
**Category:** World Creation\
**Tags:** Destroy, actor, unreal-engine, editor, question, CPP\
**Created:** [March 8, 2015, 3:10pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965 "2015-03-08T15:10:33Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![anonymous\_user\_3933a5bf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3933a5bf](https://forums.unrealengine.com/u/anonymous_user_3933a5bf)\
**Post date:** [May 29, 2015, 4:47pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/21 "2015-05-29T16:47:45Z")

</div>

This seemed to work as expected for me. When I create my child actors I make sure to set their owner as the region so when the region is ::Destroyed() it will go through all world actors that contain the same owner and call their -\>Destroy() method. Here is the code to get all child room actors w/the region as the owner:

```
TArray<ARoom*> ARegion::GetRoomActors()
{
	// get all child components
	TArray<ARoom*> result;
	for (TActorIterator<ARoom> room(GetWorld()); room; ++room)
	{
		if (!room || !room->IsValidLowLevel())
			continue;

		if (room->GetOwner() == this)
			result.Add(*room);
	}
	return result;
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3933a5bf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3933a5bf](https://forums.unrealengine.com/u/anonymous_user_3933a5bf)\
**Post date:** [May 29, 2015, 4:48pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/22 "2015-05-29T16:48:51Z")

</div>

So I avoid storing a child actor pointer array but I have to pull it from the world when I need it. I guess that is the only difference.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3933a5bf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3933a5bf](https://forums.unrealengine.com/u/anonymous_user_3933a5bf)\
**Post date:** [May 29, 2015, 4:59pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/23 "2015-05-29T16:59:00Z")

</div>

You know it would be much better if we can tell if the user is just dragging an actor into the scene so we can avoid any unnecessary construction. Is this possible?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3933a5bf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3933a5bf](https://forums.unrealengine.com/u/anonymous_user_3933a5bf)\
**Post date:** [May 29, 2015, 4:59pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/24 "2015-05-29T16:59:28Z")

</div>

You know it would be much better if we can tell if the user is just dragging an actor into the scene so we can avoid any unnecessary construction. Is this possible? I added my code below but wanted to raise the question.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [June 1, 2015, 6:13pm UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/25 "2015-06-01T18:13:25Z")

</div>

Hey -

I just want to confirm that the code you posted does in fact allow you to delete the parent actor which will automatically delete the child actors that the parent generated at creation? As for dragging into the scene creating a temporary actor, this is the expected behavior. When destroying the actor it is only destroyed via garbage collection when the engine does that operation. At that point any unrefrenced temporary actors would be destroyed. If your instances are still valid then they are not deleted.

---

<div class="post-metadata">

**Author:** ![amzn\_misterv](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/amzn_misterv/32/937721_2.png) [@amzn\_misterv](https://forums.unrealengine.com/u/amzn_misterv)\
**Post date:** [April 30, 2024, 11:52am UTC](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965/26 "2024-04-30T11:52:24Z")

</div>

Setting a variable in PreEditChange and using it in PostTransacted seems to work for me.

[Previous page](https://forums.unrealengine.com/t/react-to-editor-destroying-deleting-an-actor/309965.md?page=1)
