# On button press destroy projectiles

**URL:** <https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 26, 2019, 9:03am UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862 "2019-07-26T09:03:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 9:03am UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/1 "2019-07-26T09:03:08Z")

</div>

How could I destroy all spawned projectiles by pressing Z?

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 26, 2019, 11:49am UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/2 "2019-07-26T11:49:21Z")

</div>

Hello,

Create an event for z pressed.

Then iterate on GetAllActorOfClass (your class).

Then iterate on your array output.

To finish call destroy function in all iteration.

---

<div class="post-metadata">

**Author:** ![Jezcentral](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jezcentral](https://forums.unrealengine.com/u/Jezcentral)\
**Post date:** [July 26, 2019, 1:44pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/3 "2019-07-26T13:44:34Z")

</div>

Although GetAllActorsOfClass (see [https://docs.unrealengine.com/en-US/Gameplay/HowTo/FindingActors/Blueprints/index.html](https://docs.unrealengine.com/en-US/Gameplay/HowTo/FindingActors/Blueprints/index.html)) would work, it is very computationally intensive. It would be better to add the projectiles to an array as they are spawned, and then, on pressing the button, looping through that array, destroying the projectiles.

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 9:32pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/4 "2019-07-26T21:32:58Z")

</div>

Thank you, sounds even cooler but the player might go through a looong line of destroys because the weapon has infinite ammo. May I ask you to demonstrate the BP? I’m a bit confused here:

 ![283374-dps.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/9/29961ae0df46e6e653f0da2d9df2ada0cf0653d5.jpeg)

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 9:39pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/5 "2019-07-26T21:39:21Z")

</div>

Thanks, would you mind showing me the BP so my head can connect this theory? (I’m a total beginner).

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 26, 2019, 10:09pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/6 "2019-07-26T22:09:33Z")

</div>

On array element select node destroy actor.

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 26, 2019, 10:16pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/7 "2019-07-26T22:16:54Z")

</div>

![283368-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/8/73853263077a5f6fe7aad43977a26975986918d2.png)

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 10:19pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/8 "2019-07-26T22:19:01Z")

</div>

Oooohh… I tried deactivate. It works! Thanks!

![283375-bal.gif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/d/1cd83fa56c7300a976f03530a59a528c6e925daf.gif)

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 10:25pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/9 "2019-07-26T22:25:31Z")

</div>

Question nearby; where would I connect an explosion particle emitter (on destroy)?

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 11:29pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/10 "2019-07-26T23:29:52Z")

</div>

Thank you, it works. Is there any way to connect an explosion emitter when they’re destroyed?

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 26, 2019, 11:31pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/11 "2019-07-26T23:31:37Z")

</div>

I consider both answers as the best. (I’ll have to stick to the most simple one.) Thanks Jezcentral

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 26, 2019, 11:57pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/12 "2019-07-26T23:57:53Z")

</div>

Yes of course just get in the loop the location of your actor by get location and after call a node spawn emitter at location.

Be sure to call get actor location before destroy this one!!!

A best way to do that is to do that in thhe on destruct function in your actor class.

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 27, 2019, 12:39am UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/13 "2019-07-27T00:39:41Z")

</div>

Can’t picture it. Should I drag out the “Loop Body” pin? And then?

A sound works, but the emitter doesn’t. Why is that?

 ![283380-112.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/2/f32c2ddc303a6a8d4b39a6ff4d55b62e6503a586.jpeg)

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 27, 2019, 1:09pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/14 "2019-07-27T13:09:46Z")

</div>

You are using spawn sound a sound is a sound not a particule emitter =)

![283413-captureemitter.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/7/d/87d790cedf3e9bcb1df2b6e1e89e6cfad7fe72c4.png)

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 27, 2019, 1:42pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/15 "2019-07-27T13:42:30Z")

</div>

Sure! It should make a “■■■■■” and a visible explosion. I’ll design the sound myself.  
The emitter doesn’t work, though. ☹ can you screenshot the whole Blueprint?

 ![283414-3333.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/9/1e9a5719d6e8c57a35eb94e3f6f742457d731e62.jpeg)

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 27, 2019, 2:44pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/16 "2019-07-27T14:44:08Z")

</div>

I m sure the emitter work but you currently spawn it at location 0,0,0 if this location is under your terrain or any other place who is out of screen you will not see it.

Use actor location in the loop to spawn the emitter at the exact location of your actor.

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 27, 2019, 2:56pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/17 "2019-07-27T14:56:07Z")

</div>

In your last picture, what is the second line and location pin connected to?

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 27, 2019, 3:06pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/18 "2019-07-27T15:06:22Z")

</div>

Hit location from a line trace but in your case extend array element select node  
getActorLocation and connect it to location of emitter that should work

---

<div class="post-metadata">

**Author:** ![linkings](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@linkings](https://forums.unrealengine.com/u/linkings)\
**Post date:** [July 27, 2019, 3:27pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/19 "2019-07-27T15:27:31Z")

</div>

EDIT: OH I got it. Thanks a lot man.

![283416-rte.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/6/f/26faad7273b12b66e8715990062f848d84e0b017.jpeg)

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 27, 2019, 3:31pm UTC](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862/20 "2019-07-27T15:31:56Z")

</div>

Yes you need to extend the array element of the for each to get actor location

[Next page](https://forums.unrealengine.com/t/on-button-press-destroy-projectiles/452862.md?page=2)
