Hey !
I’m currently developping a multiplayer MOBA-style game in Blueprint with UE 5.1.1. In this game I want a zone where players can heal, only if they dont attack. Here is the code for such actor :
Just so you know, “BP_TrucQuiBouge” is a player character, and the map “CharacterCanHeal” is used to know which characters have attacked recently and which ones can be healed. If the player doesn’t attck for a duration, the healing starts (thanks to the timer and the end of “BeginOverlap”). I’m using the event dispatcher “OnSpellUsed” to know when the chracter uses a spell.
This code works fine when players are one at a time in the zone, but problems emerge when a second character enters before the end of the timer of the first entered one. In such case, the healing starts for second the second character instead of the first character (whom remains unhealed).
From what I cloud understand, it’s because the “Other Actor” reference for the character in “Begin Overlap” has changed during the timer.
As it seems impossible to pass arguments to timers in Blueprints, I’ve tried to find a solution by creating intermediate functions or events, but without success. Using delays instead of a timer doesn’t change anything neither.
I’m kinda deseperate as I don’t see any remaining solution …
i would start by separating the logic, the character should track if it can ‘heal’, this is because say later you add an invisibility zone for example, it could use the same logic. has character attacked if not can be invisible.
your heal zone can be simple, get rid of tick and just use a timer on begin play for whatever interval. when heal event is called iterate over all units in overlap and call an interface function to apply healing. now it works for anything you want to be healed.
on the actor when the interface event is called this is where you check can heal.
My main problem comes from the fact I need to track for each character an initial delay before starting the healing process (regardless of the character status). For the code given in post to work, I would need to pass parameters down to the event called by the timer. But this is impossible in Blueprints.
Right now I only see 2 solutions :
use an hand made timer for each overlapping character decrementing every tick (with a Map<Character, float> for example)
use a Queue to know which character should be healed at each timer end
But both solutions look terrible, not scalable in the future, and not performant.
I don’t understand why passing parameters down to timer callback is not already implemented in Blueprint as it is such an important feature.
To make it short, I’d like the zone to heal independently all characters inside after a short delay. This delay is reset when a character attacks or use a spell.
So yes, multiple characters can be healed at the same time. But if one attacks during the healing process, it stops (only for him), and he has to wait for the delay to end again. Regardless of the “in combat” status of the characters, they all have to wait an initial delay when entering the zone.
so one way you can do this with only one timer is to have a variable on the character called ‘healcharge’ whenever a character attacks or enters the healzone we set healcharge to 0.
then on tick/timer in the healzone we increment the healcharge by X. when X = your desired amount we apply healing and reset healcharge to 0