I’m trying to set up a battery powered flashlight and I want it to drain the battery by 1% at regular intervals.
I’ve got my int variable for the battery and I’ve set up a WhileLoop that continously reduces the BatteryPower variable by 1 while the variable is above 0. This all works great except it happens instantaneously and I want it to happen at specified intervals.
I’ve tried putting a Delay function after the whileloop and the blueprint simply gets trapped in an infinite whileloop and crashes.
What’s the right way to accomplish this?
Here’s my Blueprint for reference (Sorry about the debug text nodes):
I’d set up some variables, for control, like FlashLightDrain Started and a timepassed.
Then on a Tick Event branch on if that variable is true, you can use it’s deltatime to add up timepassed since last tick, that way you can keep it smooth. Then in the tick, when enough time has passed, set your battery power then next 1% lower.
The simplest way that I could think of would be to take a look at how the BP_SimpleMath Blueprint works inside the Content Exmaples / Blueprint_Overview map. Granted its subtracting a variable for Time, but you could use this in other ways I’m sure.