# Destroy Component not working

**URL:** <https://forums.unrealengine.com/t/destroy-component-not-working/317594>\
**Category:** World Creation\
**Tags:** Destroy, unreal-engine, Physics, Components, question\
**Created:** [May 6, 2015, 3:38am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594 "2015-05-06T03:38:18Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [May 7, 2015, 12:49am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/21 "2015-05-07T00:49:22Z")

</div>

If you’re referring to second image you posted, it’s because you’re trying to use Destroy Actor on a component that was never added. You’re using Get Children Components \> Get Owner \> Destroy Actor, but since your spawned Actor was never made a component, you’re essentially destroying nothing.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 1:45am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/22 "2015-05-07T01:45:46Z")

</div>

I’m talking about general use, not my images. When you ‘Attach Actor to Component’ object your attaching should still be an ‘Actor’.

When you try to retrieve a list of attached objects from parent, they should return ‘Actors’ but instead all that’s available is components.

So ‘Get Children Components’ \> ‘Get Owner’ \> ‘Destroy Actor’ will fail because ‘Get Children Components’ is not returning list of attached ‘Actors’ that you attached.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 2:54am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/23 "2015-05-07T02:54:24Z")

</div>

This is solution to my specific problem, but there is still an issue with understanding what ‘Attach Actor to Component’ really does and why you can’t get a list of children as Actors, only as Components.

 ![41683-working_equip.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/a/42aa3c865b3d4de369cefe450bd4d29cc46a5584.png)

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 2:56am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/24 "2015-05-07T02:56:49Z")

</div>

This also means you can’t attach more then one object at a time. You would need to build some sort of additional array to use as a make-shift ‘children’ manager.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [May 7, 2015, 3:35am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/25 "2015-05-07T03:35:05Z")

</div>

Right. Attach Actor to Component would attach an Actor to a Component. It would not turn that Actor into a Component. Those are two different categories of Objects.

You’re using Get Children Components. If instead it was a node that said Get Attached Actors, I would expect it to act as you suggest. As is, since attaching something to a component does not make it a component itself, Get Children Components should only return Components.

In case it’s not obvious, destroying Component that an Actor is attached to will not also destroy that attached Actor. That Actor will still exist, though it won’t be attached to anything anymore.

I don’t believe there’s a node for getting attached Actors. I’ll look into that tomorrow and see if that requires a feature request.

What Add Child Actor Component node does, instead, is actually create a Component as a child of Component you specify (in this case it creates a child to WeaponSlot). You can then give that node a Class in details panel. I’ll grab a screenshot of that tomorrow when I get in; we’re not looking for a variable.

Does that make sense? way I have it set up in my second screenshot should work for you once you’re able to assign Actor class you want to Add Child Actor Component node. If you’d rather not do this using Components, I can help you find a way to use attachments instead. You will need to choose one or other, though.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 4:26am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/26 "2015-05-07T04:26:35Z")

</div>

Is there a reason to have Actors and Components, isn’t an Actor just a Component with a transform?

If so, it would be better to simply make Actor a derivative of Component which would allow using component destroy on actors.

Seems overly complicated in its current setup.

As for fixing my project specific issue, I’ve already implemented an alternative using a single variable, posted as an answer.

---

<div class="post-metadata">

**Author:** ![Emidee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emidee](https://forums.unrealengine.com/u/Emidee)\
**Post date:** [May 7, 2015, 6:10am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/27 "2015-05-07T06:10:56Z")

</div>

This is solution I gave you in a comment before…

---

<div class="post-metadata">

**Author:** ![Emidee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emidee](https://forums.unrealengine.com/u/Emidee)\
**Post date:** [May 7, 2015, 6:13am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/28 "2015-05-07T06:13:50Z")

</div>

An actor holds a list of components only. only way to hold some actors is through a component named ChildActorComponent.

So no, there’s no way to get a list of **children** actors, because it makes no sense.

But to get a list of **attached** actors, I agree this could make sense.

And yes, if you want to attach multiple actors to a parent actor, you would need to maintain an array of actors in parent.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 6:28am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/29 "2015-05-07T06:28:18Z")

</div>

Yes i know, i acknowledged you already, i said “There are a few workarounds i could use” this is one of those workarounds.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 7, 2015, 6:30am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/30 "2015-05-07T06:30:01Z")

</div>

I wanted a list of attached actors, which is apparently not possible yet. Hopefully they can fix up some of confusion in this collection of nodes to make them easily understandable, and provide any missing functionality.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [May 7, 2015, 7:17pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/31 "2015-05-07T19:17:15Z")

</div>

No, Actors and Components both derive from Object, and Component steals a bit of functionality from Actor, but their relationship with each other is closer to siblings than parent/child. That may change at some point in future, but there’s no current timeline for that.

I’ve entered a feature request for a Get Attached node (UE-15211), as I can see that being useful in cases such as this.

Regardless, Destroy Component is working as intended, so we’ll go ahead and resolve this post. I’m glad you were able to find a setup that works for you.

---

<div class="post-metadata">

**Author:** ![Neros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neros](https://forums.unrealengine.com/u/Neros)\
**Post date:** [May 8, 2015, 12:12am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/32 "2015-05-08T00:12:03Z")

</div>

Thanks,

---

<div class="post-metadata">

**Author:** ![kreshnov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kreshnov](https://forums.unrealengine.com/u/kreshnov)\
**Post date:** [June 18, 2018, 6:10pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/33 "2018-06-18T18:10:49Z")

</div>

I had a similar problem, only in my case only SOME elements were removed.  
Here’s my 2 cents:

When you iterate over an array and remove each element in it, array itself shrinks in process and elements inside shift.  
Say I have a 2-element array and I’ve destroyed first one, array will shrink to a 1-element size and that element will be placed in first array position.  
By time I call second iteration and try to remove element in second position, it will be empty and element is not destroyed.

So there are 2 solutions to this problem:

1. Destroy elements in reverse order so nothing is shifted.
2. Use a While loop, each time on first element until array is empty. Please see attached image.

 ![244723-untitled-2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/8/358ba0b959576c8f08bf278955aecc29cc31c507.jpeg)

---

<div class="post-metadata">

**Author:** ![Orion\_78](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Orion\_78](https://forums.unrealengine.com/u/Orion_78)\
**Post date:** [October 9, 2019, 8:26am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/34 "2019-10-09T08:26:27Z")

</div>

It doesn’t destroy because you are not owner. You can self destroy it or destroy it from an event from owner actor

---

<div class="post-metadata">

**Author:** ![Orion\_78](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Orion\_78](https://forums.unrealengine.com/u/Orion_78)\
**Post date:** [October 9, 2019, 8:26am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/35 "2019-10-09T08:26:35Z")

</div>

It doesn’t destroy because you are not owner. You can self destroy it or destroy it from an event from owner actor

---

<div class="post-metadata">

**Author:** ![PeaceSells](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/peacesells/32/778010_2.png) [@PeaceSells](https://forums.unrealengine.com/u/PeaceSells)\
**Post date:** [November 9, 2020, 8:58pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/36 "2020-11-09T20:58:49Z")

</div>

Thank you kreshnov, you solved my issue!

---

<div class="post-metadata">

**Author:** ![Elfideo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Elfideo](https://forums.unrealengine.com/u/Elfideo)\
**Post date:** [July 18, 2021, 3:16pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/37 "2021-07-18T15:16:01Z")

</div>

Hey I was suffering with same problem you were having, I was trying to delete static actor attached with an anim notify and this is way to solve it.

Just for future in case pic get’s erased  
Received notify(MeshComponent)-\>GetOwner-\>AttachedActors-\>ForEachLoop(ArrayElement)-\>DestroyActor.

 ![344422-destroyattachedactors.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/8/4d8047b248161dd1f00c01d7d88c279e38e37890.png)

---

<div class="post-metadata">

**Author:** ![Ares9323](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ares9323/32/1194521_2.png) [@Ares9323](https://forums.unrealengine.com/u/Ares9323)\
**Post date:** [November 27, 2021, 6:28pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/38 "2021-11-27T18:28:45Z")

</div>

If you are trying to destroy all the actors/components in a scene you can’t connect “GetChildrenComponents()” directly to for each loop.  
Every time you destroy a component in the loop, the GetChildrenComponents() function is called again but the index continues to increase, and because of this behaviour, only a half of the components is destroyed.

To solve this just store result form GetChildrenComponents() into a local variable and then run foreach from it.

**Example:**

 ![353150-bpgraphscreenshot-2021y-11m-27d-19h-26m-13s-899-00.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/e/5cebc6dfbf4840336772ebcdf8023943c5747f22.jpeg)

* * *

Edit: Something I recently discovered is that you can use local variables without names and obtain the same result as shown in the screenshot above (This is useful when you are in the event graph and cannot create local variables, like in functions and constructors).

In this way you don’t clutter your variable list with something that you only need in a single event/macro. Obviously, if you are inside a function, “real” local variables are a better option.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/b/28b1d20674d3fdfd83ef5bc94ea4f87dd6654eb2.png).

---

<div class="post-metadata">

**Author:** ![MionZone](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MionZone](https://forums.unrealengine.com/u/MionZone)\
**Post date:** [May 11, 2023, 7:09am UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/39 "2023-05-11T07:09:47Z")

</div>

This is the correct answer.

---

<div class="post-metadata">

**Author:** ![Nizami\_Nz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nizami\_Nz](https://forums.unrealengine.com/u/Nizami_Nz)\
**Post date:** [June 27, 2023, 7:18pm UTC](https://forums.unrealengine.com/t/destroy-component-not-working/317594/40 "2023-06-27T19:18:33Z")

</div>

What helped in my case was that I called (DestroyComponent) in (OwnerActor of Component)

 ![011](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/1/7c1f415458735f422f4021f3340f87581da9b851.png)  
 ![01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/8/668d9b674861494263313d03d661a2ae2c5d4993.png)

[Previous page](https://forums.unrealengine.com/t/destroy-component-not-working/317594.md?page=1)

[Next page](https://forums.unrealengine.com/t/destroy-component-not-working/317594.md?page=3)
