Destroy Component does not work

I am trying to destroy child components of an actor blueprint, which are of a certain height and when DestroyComponent is called, they remain on the screen. I know the function is called after debugging so it is supposed to work. The actors are made of 3 or 4 child Spheres, who have box colliders. This is my script:

I have tried casting to StaticMeshComponent before calling DestroyComponent but it did not work, and I have tried with checking “Include All Descendants” while enumerating the child components and it did not work either.

Try storing the resultant arrays (GetAllActorsOfClass) and (GetChildrenComponents) locally before entering each Loop. In your current logic, each Loop iteration will call the nodes “GetChildrenComponents” or GetAllActorsOfClass, this can lead to unexpected results cause they are being modified on each iteration.

Another thing you should consider is that each DestroyComponent call could be rearranging the Children Array. You can try a reverse Loop, starting from the last index and ending on first.

OK the problem I found out was I was calling DestroyComponent from outside the actor class, I made a function that destroys the children from inside the actor class and it partially worked. There are still components not being destroyed. Does calling DestroyComponent remove the component from the array? Because the array seems to stay the same in the loop.


This works, thanks!

I know this thread is quite old, but I exactly had the same issue…

It’s not possible to destroy an ActorComponent from outside of the owning actor from Blueprints. So a huge question came into my mind, why can I call this frunction, from the outside of an actor if it does not do anything (it’s a public method :slight_smile:)?!?
And in the log I found “May not destroy component”, so it is destroyed or not? :slight_smile:

Looking deeper into the engine code it’s clear that the component is not destroyed if “bAllowAnyoneToDestroyMe” is not set to true (1) or the method is not called in the context of the owning actor.

Sadly “bAllowAnyoneToDestroyMe” is not exposed to Blueprints. :frowning:

So I decided to create a proper solution to force the destruction within a BlueprintFunctionLibrary.
Here is the code: Force Unreal Engine Actor Component Destruction from Blueprints · GitHub.



but where do I paste your code :sweat_smile:
actually when I play test the actor are gone
just still show the annoyed warning