So I made this reusable timer macro that works fine in itself. The problem arose when I came up with the idea to add a while loop to the timer so I can basically run a tick only when the timer is active… seems like it would be extremely useful.
I think this should work but whenever I activate the timer, the while loop complains about an “infinite loop”. This makes no sense to me because when the timer is not active or when it is cleared, the elapsed time is -1, and since I have the “>=” condition, it should not be an infinite while loop??? Help!
Is it possible that Get Timer Elapsed Time by Function Name never returns a negative number? That would prevent this from ever existing. You could try changing it to while (A > 0.f) rather then while (A >= 0.f).
Also just wondering where this would be useful. I’m still new and have not run into a place in which I would use something like this.
I put a print string right after the “Get elapsed time” node and it does return -1 when the timer isn’t active or when it is reset. And if I put it as “>” instead of “>=” it would never activate the while loop because the execution to it gets ran when the elapsed time is at 0.
I feel like the while loops in Blueprint are pretty much useless I have coded some text based games for myself in pure C++ Visual Studio Code and in that while loops are very useful and make sense.
So there is no way to do it with purely this while loop method then, sucks… I guess I could give the gate a go at some point. Thanks for replying anyways
EDIT: Yeah so I tried the gate and it’s the same thing unfortunately. Thanks for the suggestion tho.
Hmm, but what if I need a constant tick running as well? I assume then pausing the tick will pause it for everything in that Blueprint and there is no easy way to have two ticks essentially with one running and one paused?
So I ended up doing a workaround where I run the normal tick from the Blueprint through the timer macro. This way I can split it into other places with a sequence node and get the tick from the timer when it is running. Not ideal but I guess it’ll do…
Yeah, I’m kinda new to Blueprint so I don’t get these things since I’m used to working in C and C++. Btw do you think something like my original plan could be possible to do in C++ script, or is it gonna be the same story since it is still used inside UE4? And would it even be a good idea to try it or do you think it will be too risky?
Alright man, thanks for the tips. I think I’ll stick to my workaround for now since it does the job and isn’t too sketchy I have it in my head tho that at some point I do want to switch over to using C++ scripts too since they are much faster than BP.
Hmm, good to know. I will surely look more into all of this when I decide to delve into C++ scripts. I’ll be sure to keep custom tick functions in my mind
Forget my last one; I went with your method and improved it a lot imo. Using the “Set Timer By Function Name” makes it much simpler because the function/event doesn’t need to be connected to the macro. I added functionality so that if the function name changes, it clears the last timer before setting the new one.