I’m going through the official “Blueprint twin stick shooter” tutorial and have a question about events.
Quick background, since it’s not super relevant: I’m a professional C++ dev, but my only gaming background are hobby projects made 100% from scratch. I want to actually get something done, so I’m diving into UE4. I’m starting with blueprints to try and learn the fundamentals of how things are supposed to fit together, and then I’ll probably switch to C++. (Side question: is this a good idea, or should I just go straight to C++? so far it seems there’s way more “learn UE4” information centered around blueprints, so that’s where I decided to start)
Here’s the actual blueprint I’ll be referencing:
Here, when these objects overlap, he stores the “Hero” as a variable, and sets a timer to hit an event repeatedly until the object is no longer overlap a “HeroCharacter” object. While this timer is running, it damages the stored “Hero” variable.
My question is more theoretical/about “clean code” rather than practical for this project (and maybe worrying about these things is why I can’t ever finish a game on my own). Say there were multiple heroes. How I would want this to act, is that every hero in range would be damaged their own timer, based on when they came in range of the enemy. How I’m guessing this acts is that when any hero is intersected, it starts the timer. From then on, any subsequent hero entering the intersection will replace the single, member-variable “Hero”, and thus will be the only one taking damage from that point on. I’m not sure what happens to the timer, I’m assuming it just gets reset when another hero object intersects (cancels and restarts). What I think should happen, is every hero entering should spawn its own timer, and that timer should hit an event that damages that hero and that timer should be canceled only when that hero is no longer overlapped.
The obvious solution to me is: Have the “DamageTheHero” event take a “hero” as a parameter, rather than storing a single “hero” as a member. The timer would then schedule a closure with that hero parameter captured, which gets called every n seconds (0.5 in the tutorial). This doesn’t seem to be possible, since timers seem like they only work with events that take no parameters. Is there any way to do this in blueprints, or am I trying to stretch blueprints too far? Will this be easy to do if I were to convert this all to C++? Would I be able to create a generic “Timer” blueprint that supports capturing variables to pass to parameterized events?
For the “EndOverlap” part, ideally on the “BeginOverlap” event I’d be able to say “when this overlap ends, launch x event” where “x” is an event that captures that timer (that I have a local reference to, since I’d still be in “BeginOverlap” when doing the capture) in the “set” event, and when it is triggered it simply cancels the timer. Less ideally, I’d store a map of actor references → timers, lookup the actor and cancel the timer if it’s found (which would mean an expensive map lookup that really does not need to happen). I assume the latter will certainly be possible when I delve into UE C++, but is the former possible?