Destroying actor destroys all other actors of the same blueprint

In my Blueprint script, I have a UMG button which should destroy the actor that the mouse is hovering over. The UMG widget is displayed where ever the right mouses button is clicked.

I have added a binded event to the button that is set to destroy the actor however when this button is pressed, it destroys all the actors that use the same blueprint.

Left of this is simply casting to player and player controller attached to an On Event Begin Play node. Max nuimber of uploads has been reached.

I don’t know what I am doing wrong but I just want the actor that the mouse is over to be destroyed.I can provide more information if needed. Thanks in advance as well.

Could you show the rest of the blueprint as well?

So far it looks like you made a mistake when doing the binding so it’ll always trigger when you click that button which then will destroy each actor because your “AtLocation” is inside of the playercontroller and will always provide the same result for all actors in your level.

Cheers

I’ve added a more screenshots.

Where is the part directly left from the first picture? That would be the most interesting right now :slight_smile:

34719-

Alright so there we go.

Inside of your item during the event begin play you bind the button of the widget which belongs to the character to an event.

You do this for every item always so when this button is clicked every item will receive the event call, do the “Check coordinates” (which doesn’t take the current actor location as input so it just checks something and moves to the mouse location) and then asks if the bool “AtLocation” is true. But when you are setting it true it will be true for every single actor of this type because they all look at the same variable so all get destroyed.

There are two nice ways to fix this.

  1. You only bind the event in your item after you clicked on it and unbind it again when you click on something else. The event OnClicked should work quite well.
  2. Make your “CheckCoordinates” actually check the current mouse coordinates and compare those to the item. If it’s close only destroy that one.

The first solution is quite a bit better because it scales well. No matter how many items you have in your level only the one you are working with will execute it’s code. The others will just do nothing so I would suggest doing that.

Cheers :slight_smile:

Thank you very much.