Remove item from array after duration

Hi. I want to create a damage system where specific projectiles have a “cooldown” on their ability to hurt specific players. Here is a gfy showing how my game works (don’t think you can embed gfys?):

…except now the boomerang passes through players when it hits them. The problem with this is that the boomerang can hit a player (and then deal damage to them), pass through them and immediately return and deal more damage. While this is okay if the boomerang travels a lot between the two hits, it’s undesirable when the two happen almost one after another. I’ve built this project in Unity before, and what I did was the following:

  • When a player is hit, add that player to a dictionay with the key being the player, and the value being the time it was hit
  • When another player is hit, check the dictionary to see if the contacted player is a member. If it is, check if the time has elapsed where it’s okay to damage them again
  • If the time HAS elapsed, damage the player again and update the time. If not, ignore them

…but there doesn’t seem to be a dictionary structure in Blueprints. There are arrays however, so in theory I could add a player to the array, and then fire off a timer that would remove it after n seconds. SetTimer does this, but I don’t think I could pass an actor to it’s function as a parameter. Is there any way to achieve what I want through Blueprints? My prototype is almost done so I’d ideally not want to switch to C++ at the moment.


Hello and welcome! You can try this: Make an array like you said, and a custom event. In the custom event, add the player as an argument. Then after adding the player to the array, execute the custom event. The custom event should start with a delay of n seconds, and then remove the player (taken from the argument/input) from your array.

Hey Dj, thanks for the reply. That almost worked! The issue is that it seems only one instance of a custom event can be active at any time. So if the blade hits two players and the cooldown begins on both, the second time the event fires it cancels out the first. I ended up just using two arrays: one to hold all the players, and one to hold the times they were struck, with both at the same indices in their respective arrays. This way I can make a pseudo dictionary that does what I want.

Dictionary is a TMap structure in UE4. (It is a pair of Key (hit actor) and value (time delay)). Unfortunately there is no support for it in blueprints, but still you can implement some usage in C++.

My bad, I thought it should work that way. Well I’m glad you solved it. Good luck to you :slight_smile: