Have weapon fire rate faster than tick

I’ve been really careful trying to make sure any calculations I’ve been doing regarding physics, health regen, etc. utilises delta time in some way to keep things independent from the frame rate. However I’ve run into a bit of an issue I can’t seem to resolve, and I’m surprised there hasn’t been a single thread on the issue, even from complete beginners.

How can you make a weapon fire at the same speed REGARDLESS of the tick rate?

Mind you, my system EASILY handles UE4 at 60fps, but not everyone has that luxury. And I know, a weapon firing more than 60 times per second seems STUPIDLY high, but it’s still a problem if you had a minigun that has a high fire rate.

Any ideas on solving this issue, or am I just gonna have to make sure any and all weapons I ever create never fire faster than the absolute lowest fps I can see someone getting in the engine?

You turn on sub-stepping.

Hi SirChronocide,

Try using timers instead of tick. You can set timers to fire off at specific intervals, even if the intervals are extremely short. To get a firemode roughly the equivalent of 60 fps, try .08 and set it to looping. See if this works for what you are looking for.

It is worth noting that timers cannot fire off at intervals higher than the Tick rate. Example (outputting GetWorld()->GetTimeSeconds() when the timer fires):

Sorry, should’ve mentioned this more specifically. I am NOT tying anything to Tick; I avoid it as MUCH as possible. I use timelines and timers wherever I can and it seems like it doesn’t make a difference.

When I get an fire input, I set a boolean isFiring to true, start my firing timeline, and have it check if that boolean is true and have it iterate through my usual firing procedure; then adds I add a delay equal to the firerate/sec (for example 0.1). After the delay, it loops back into the initial isFiring check. Once isFiring is set the false, it stops the timeline.

Just use timers.

I’m assuming that’s because GetTimeSeconds() gets updated once each tick, not because the timer doesn’t work faster than frame rate.

Take a look at this, let’s assume you want a minigun shooting 6000 rounds per minute. That’s 100 per second, but since this is a very fast minigun it’s going to shoot 1000 rounds per second, just because I get framerates in the hundreds.

As you can see, the shooting event gets called 5000 times in the span of 5 seconds, a lot more than once per tick. A thing to note is that since you’re dealing with very small floating point numbers you’ll get some errors, in my tests I got numbers like 5002 or 5003 instead of just 5000.

This is wrong. The event will be called 5001 times in one frame. You can call an event more than once in a frame, but you can’t call it between N - N + 0.0166667 space. I hope someone corrects me because I kinda need it myself personally. :stuck_out_tongue:

Uhm i understand your problem, but that timer solution sounds… strange? to me.

At 60 FPS with a Target of 6.000 Bullets/s:
100 / Delta Time = X
=> Shoot X Bullets / Tick

I mean, wheres the difference if you shoot 100 bullets / tick or 100 bullets between ticks, it does get rendered only 1 time each tick anyway…?
That’s why the delta time is there, to calculate such stuff. No need for threaded timers.

Not sure if I follow you. What SirChronocide asked for was a way to call functions at an arbitrary interval regardless of framerate and that’s what timers do.

Agree, calculating the number of bullets that should be spawned on each tick depending on delta time is the more sensible choice. But if for some reason he really needs to call events on micro intervals it’s good to know that timers work and are very reliable.

Timers are better. As soon as you start using things like Custom Time Dilation, The Tick Event starts behaving differently.

If you want projectiles to fire that quickly, you need some kind of substepping system, where you break up a frame into multiple chunks and spawn the projectiles in offset positions accordingly.

Problem is he is trying to make a minigun. And if he uses timer or timeline, every event will be triggered on every frame minimum. So if you arrange a timer that triggers 2 times each 0.008 seconds, the event will trigger only once. If you make it very small, such as 0.001 seconds, it will trigger twice in the same frame and this will still cause the event to trigger 2 times at the same time just duplicating the event, sound, hit, etc.

I will be honest though, a minigun that is firing each 0.0166667 seconds is still fast. :stuck_out_tongue: