deleting an item when in range and with the key press "E"

got most of the code on the left from a tutorial and I would like to reuse it to also delete the item under certain circumstances.

what’s wrong with my code?

I want it to delete the item when it is in range and E is pressed

thanks a ton!

1 Like

that’s not exactly how code works.

you’ll need to connect the branch node to the E event
and set the “kill item” variable on begin overlap and end overlap.

imho i will discourage connect things among different events and functions (like you have that widget and kill item variable).
that’s leads to spaghettification.


I wrote a blueprint for you, you can do it like me.
Red box: Destroy can only be triggered when the player is in range (you need to set a tag for your player) to prevent it from being triggered when an NPC character enters the range.
Blue box + Green box: Allow the player to press E to destroy it
Yellow box: Make the destruction only execute once to prevent multiple triggers.

1 Like

IMO:

  • Actors shouldn’t handle input directly. Input should be managed by the PlayerController or Pawn.
  • Might be better to check if the overlapped pawn is player controlled, not a tag.
  • Might not work if the player is overlapping multiple items.

You are right, but it may be too complicated for a beginner to handle.
I would just modify it on what he currently does. At least make it work first.

Avoiding complexity now could be kicking the can down the road.


I would change the code to this: Move E input to the player character. On press check for overlapping actors with interface to execute.

@CyberPanda1670 please let us now if you need help on how to do this.

Agree. E is working as an interaction subsystem, so it should be implemented as such.

1 Like

Sorry for the delayed response. As a beginner, yes, I would like an explanation on how to make this possible. Also thank you guys for taking the time to help me w/ this!

With inspiration from ideas you guys suggested, I stitched it together with a cool video on youtube I found and it works great!!

the picture above is the exact code I used incase any future onlookers want to know. Hello onlookers!

Multiplayer (Server Authority) key press interaction

subbed!

1 Like