I want to destroy the actor 11 with all attached actors, how to do this in blueprint
thanks
Something like this perhaps:
or simply you can destroyactor with “self” as target
I was coincidentally trying to do it the same way as the above screenshot, but only certain actors (about half) were being removed. It seems that in the process of destroying the attached actors, it would automatically rename the existing actors which would throw off the GetAttachedActors array. To fix this, all I did was use a reverse ForEachLoop so ue4 wouldn’t rename things along the way and viola it works!
i dont think things would get renames its more that when you delete an item from an array the rest of the array data shifts. so if you delete index 5 then the index 6 would shift and become 5 creating a cascading affect. this is why reverse loops are perfect for removing data from arrays
Thanks for clarifying that - that does make much more sense!
I had an issue similar to this. In my case the enemy AI is a character and the weapon of the AI is made in a different Actor blueprint(Weapon_Base). So I spawn these weapons to a socket on the enemy AI.
Now here is the destroying part:
- I destroy the enemy AI blueprint (with destroy self)
- I promote the output of the spawned actor from class to a variable, and set this
- Destroy the spawned actor by plugging it in another destroy node!
Now each time I kill the enemy AI, his weapon also gets destroyed.
Hope this helps you.
It worked perfectly. Thank you
Is there a good reason for using for loops in this particular case? I like to keep it simple
I would like to pay you. Been searching and fighting with this for WEEKS.
For some reason, it doesn’t get all actors for me?!? it removes some, but not all?? Only when I run it multiple times does it work? even tried adding garbage collection node but no luck.
Get all actors of class works, but get attached actors fails
my guess would be when you destroy something on a loop it breaks the loop, for instance if you destroy index 2, index 3 becomes index 2 and gets skipped.
you can try a reverse loop or try caching the actors to destroy in a local variable
Did it not work to promote all attached actors to vars and destroy rhose vars after the primary actor destroys? Works like a charm for me! My setup isnt overly complicated tho.
Sounds possible. I noticed it would skip every second index. For now my other method, get class works like a charm. It’s the exact same setup, but using the get all actors of class instead of get attached actors.
get all actors could be problematic, for instance it could get attachments off a different actor.
i think the best way to handle it is have the child actor bind to its parents ondestroyed event and then destroy itself.
that way its self contained and modular
True, but for now it’s not a problem. I will worry about it later. Only annoyance I have is that the actor names do not reset to 1 and have numbers such as 834. I use Spawnactor.
Here is an image of my current results, I use procedural mesh section to create a hexagon planet. I still have to do the normals and uv’s:
This worked for me