x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Timers ARE dependent on framerate?

I'm programming a gun for my game in c++ UE4.13. I'm using Timers to handle the time between firing bullets, similar to the ShooterTutorial.

I've noticed that my weapon's firing rates vary depending on the framerate. This is especially noticeable on fast firing weapons.

I tried the same thing on the ShooterTutorial and I noticed the same problem. I even took a video: https://www.youtube.com/watch?v=tXsVe7y5XwM&feature=youtu.be (I set the machinegun to have a TimeBetweenShots to 0.075, the same firerate as the weapon in my game), the gun shoots significantly slower on 10fps than 30fps. It takes about 5 seconds to fire 50 bullets in 10fps, but 3.40 seconds to do the same on 30fps.

Are timers bad for weapon fire rates? I know it's not likely for someone to play a game at 10fps, but it's not unusual for a game to drop to 25 fps and even then it's noticeably shooting slower. It definitely feels like it shoots faster on high framerates too (but my computer can't record consistently at a high fps so I couldn't really test it).

TLDR: Using timers to handle weapon fire rates. Rapid fire weapons shoot noticeably slower during low framerates. Is this a bug or is there a better way to handle fast shooting weapons?

Any help is appreciated. Thanks in advance! :)

Product Version: UE 4.13
Tags:
more ▼

asked Oct 19 '16 at 05:09 AM in C++ Programming

avatar image

wilsonc
37 1 3 6

avatar image TX549 Oct 19 '16 at 05:12 AM

Are you using Tick to drive the timer? My guess is it has something to do with Tick which is driven by the time taken to render the previous frame. I'm checking source code, but are you doing this in c++ or blueprints?

avatar image wilsonc Oct 19 '16 at 05:37 AM

All in C++. I don't have anything in tick in my weapon class. The ShooterTutorial doesn't either... so I'm not sure if it's a bug or if timers were never meant to be used that way :/

avatar image TX549 Oct 19 '16 at 05:42 AM

Tick is being used under the hood by FTimerManager. I could have sworn it wasn't frame rate dependent but it might be. What is the frame rate drop in your video caused by? The tick/timer could be getting held up by some other program execution.

avatar image wilsonc Oct 19 '16 at 05:54 AM

I've noticed the FPS drops when I have too many entities on screen. However in the video I posted above I used t.maxfps in the console to limit the framerate to 10 and the gun was consistently firing slower than when i tried t.maxfps 30.

avatar image TX549 Oct 19 '16 at 05:56 AM

That might be a specific case where you're changing an internal engine variable that the tick event is driven off of. Timers should be frame rate independent but capping the frame rate in the engine like that might be different.

avatar image wilsonc Oct 30 '16 at 12:42 AM

UPDATE:

After further testing, I've noticed EVERYTHING in my game becomes slower on low framerates - I've tested dropping physics objects, player movement etc. Even at 30 fps everything is much slower than at 60. I've tried it in the ShooterTutorial as well, but it isn't really noticeable unless it drops to extremely low fps (under 10).

Anyone else experience this? My game's framerate settings are left at default. I'm using 4.13. Could this possibly be an engine bug?

alt text

frameratetest.jpg (17.8 kB)
avatar image TX549 Nov 07 '16 at 01:59 PM

It's just a part of the engine and computing in general. Framerate and rendering a frame is part of the work the game engine does every time it runs through a tick/cycle. So if you have some cpu operation that forces the thread or system to wait for a second it's going to take that second before it moves on to updating physics, frame render, or anything else. It usually happens so quick you don't notice that each thing is updated sequentially, but when that cpu crunch happens it's slowing down the whole system, not just camera renders.

avatar image wilsonc Nov 07 '16 at 07:00 PM

Sorry I'm not sure I understand :/

I don't believe I'm forcing the engine to "wait" for anything, shouldn't it still be running tick every frame? I'm not making it count number of frames but delta seconds so it shouldn't be affected by fps.

For example I have a weapon that should fire 10 bullets a second (timer value of 0.1 before the next bullet fires). At 10 fps it should still be firing on time at 1 bullet per frame but it definitely can't keep up. At 20 fps it still is noticeably slower even though it has more than enough ticks per second.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

No there is an option to set up a timer that works off of a variable and uses the value of the value as seconds so if you had a float with a value of 30 the timer would be set to thirty seconds.

more ▼

answered Oct 19 '16 at 06:05 AM

avatar image

Krogalios
3 1 1

avatar image wilsonc Oct 19 '16 at 06:32 AM

Yup that's what my code does and so does the ShooterTutorial.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You could define Tick(float deltaSeconds) on the actor, in this case the gun. It's a virtual function so you would have to override it, but you could just have the gun keep track of when it last fired and have the time since last shot variable get updated every tick. Essentially:

 void Tick(float deltaSeconds){
   fTimeSinceLastFire += deltaSeconds;
 }

 void FireWeapon(){
   if(fTimeSinceLastFire >= WeaponCooldown){
       Weapon->Fire();
   }
 }

This might be more helpful if you still want to use timers: http://www.tomlooman.com/using-timers-in-ue4/

more ▼

answered Oct 19 '16 at 06:17 AM

avatar image

TX549
33 2 3 3

avatar image wilsonc Oct 19 '16 at 06:34 AM

Yeah I think I'm gonna try running it in tick and see if it has the same issue.

avatar image staticvoidlol Nov 08 '16 at 10:37 AM

Just a note, you should always include a call to super when overriding Tick, e.g.

 void Tick(float deltaSeconds)
 {
     // Call super
     Super::Tick(deltaSeconds);
     
     // Do my own stuff
     fTimeSinceLastFire += deltaSeconds;
  }

Otherwise you might be missing some critical update logic happening in the parent class.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question