We are currently developing a school project in which, by pressing the ket “t” you get teleported to a random possition inside a certain area.
We are setting this ability to only work every 20 secconds and its working fine:
But now, we need a cooldown bar where, when used such ability (by pressing the “t” key), gets drained and while the 20 secconds are running, the bar keeps filling up (continuously) until the point where its filles again.
(This means that the teleport ability is ready)
(This means that the teleport ability is currently on a cooldown window)
We´ve tried a lot but cant get to a propper solution, heres the setup we are using in a progress bar widget:
Set timer event is the way for such thing.
It’s allow you to execute a fonction X time / per second, and the best way to handle you’r ability.
But you can also work with setting a float to 20,
Then decremente it by current delta time in a tick function,
When it reach 0 (Or less than 0) it mean you have spend 20 second, but also allow you to fill you’re progress bar.
For performance reason, i don’t recommande you to go with a tick fonction, but with set timer.
After, in reality, using tick for updating you’re UI, until you have a ton of UI, is totally fine.
Timer will give you more control as, unlike the
Delay node, it actually keeps track of the elapsed time (timer is a glorified delay). Consider the following:
Gated is a reasonable compromise between having things updated every frame (you want to update the progress every frame after all) and not wasting performance. Here we only update the progress bar during cooldown.
Your approach to obtaining a reference to a widget is not great, but that’s another topic. Why not create the widget in entity that is actively using it?