Destroy Component not working

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.

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.

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.

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.

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.

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.

This is solution I gave you in a comment before…

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.

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

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.

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.

Thanks,

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.

3 Likes

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

2 Likes

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

Thank you kreshnov, you solved my issue!

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.

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:


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.

.

4 Likes

This is the correct answer.

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