I’m having a problem with the timer I’ve implemented in my blueprint system.
My plan is to create a spell that only finishes as long as the player keeps pressing the button until the spell blueprint has done all it’s functionality. If the button would be released before that, the timer would reset and the player should start over.
This is basically what happens in my Character Blueprint
I’m calling the function SpellTimer as a result of player input.
That function’s purpose is to activate or clear the timer based on if the key is pressed or not. The SpellInvocationTime you see as a variable is set to 5 seconds.
Okay… Now my plan is to spawn the ParticleSystem Actor which really is the spell the character is casting.
At the very beginning of every loop I’m commanding a check to see if the timer I activate in Character blueprint or not. As I mentioned earlier, If the key is released the spell cancels and if not it will continue.
This is the place where the problems appear.
If I completely ignore the IsTimerActive -check, the loop works fine and I get the result I want… Without the key holding effect.
As I have debugged it slightly by myself it seems that the IsTimerActive-value is constantly False which results to skipping the loop at the first step.
Also the other thing I noticed while debugging it is that if I GetTimerElapsedTime it shows me value of -1 before ending the loop.
I’m really out of ideas as to where to look for a solution to get the timer be active and as a result cause the spell work as I want.
I appreciate any help, thank you in beforehand!
You’ve forgotten to tell your Timer nodes which function should be invoked or cleared. Currently the SetTimer/ClearTimer nodes’ Function Name property is empty. Judging by your IsTimerActive check you’ll want to enter SpellTimer there. Note that SpellTimer needs to actually exist as a function in the character.
I don’t understand the purpose of the ForEachLoopForDelay node, though. Maybe you use it for something else (UI or particle effects, maybe), but if it’s just for keeping track of the timer the other nodes should be enough. When the player starts pressing the button, the timer is started. When the player releases the button, the timer is cancelled. And when the player has continuously been pressing the button for Spell Invocation Time seconds, the SpellTimer function is called, so you can trigger your actual spell effects there.
The purpose of ForEachLoopForDelay (which is a custom loop) is to go through all the actor components and set them from hidden to not hidden one by one with certain time interval. So it doesn’t actually have anything to do with the timer setup. It was just necessity to get delay to function inside the loop body.
The plan is not to have player keep certain button pressed before activating the spell but to have one keep the button pressed at the very same time as the spell goes on. If released, the spell should abrupt.
I want the timer to run at the same time as the spell is being cast - no matter how long the spell or what kind of spell. That is why I can’t implement SpellTimer inside the loop but it must be outside of it.
If I can’t use Timer setup like this - do you know if there is any other way of achieving the result with the idea I mentioned earlier?
I’m wondering if I should check out how to make custom counters to replace Timer-nodes…
Edit Figured just out how to go around it. The following thread was most helpful. (Completed!) How can I count the seconds that we keep a key pressed? - Programming & Scripting - Epic Developer Community Forums
Thank you for pointing out my mistake with the timer node!