Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SamohtVII · Oct 16, 2018 at 12:29 AM · framerate

Run Update at a constant framerate in a single script

I have a ghost script that replays a users car movement. If it records at 30FPS and then performance increases to 60FPS the recording plays twice as fast. Is it possible to tell my update in my ghost script to run at like 15 FPS?

I don't require a high FPS as the tween between frames is fine. Also the 30 and 60 FPS are just example numbers.

The rest of my game can run at whatever FPS it requires but I want my ghost script to be fixed so the replay is always the same speed.

Will FixedUpdate do what I need?

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by IvovdMarel · Oct 16, 2018 at 12:47 AM

Yes FixedUpdate will do what you need.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html

https://unity3d.com/learn/tutorials/topics/scripting/update-and-fixedupdate

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 16, 2018 at 12:51 AM 0
Share

FixedUpdate is actually the physics tick and should only be used for that. Changing the fixedDeltaTime will affect physics simulation. By default the physics framerate / deltaTime is set to 50 fps (0.02s).

avatar image
0

Answer by Bunny83 · Oct 16, 2018 at 12:52 AM

Instead of FixedUpdate you may want to use a custom fixed update callback.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SamohtVII · Oct 16, 2018 at 01:42 AM 0
Share

I might try this and save on unnecessarily frequent saving. I think i can get away with 10 times per second rather that however many fixed update runs. Thanks

avatar image
0

Answer by Lagger625 · Oct 16, 2018 at 12:57 AM

FixedUpdate can do the trick, it runs at 50 FPS with default fixed timestep setting, wich is 0.02. Or you can use coroutines for this. Like following pseudocode:

 void StartPlayback(){
        StartCoroutine(Playback());
 }
 
 IEnumerator Playback(){
        do {
               ///////////////////////
               // playback logic here
               ///////////////////////
               yield return new WaitForSeconds(1f / 30f);
       } while (playbackNotFinished);
 }
 
 void StopPlayback(){
        StopCoroutine(Playback());
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 16, 2018 at 01:02 AM 0
Share

Coroutines wouldn't be very accurate for this, especially when the framerate isn't at least some multiples higher than your desired rate. $$anonymous$$y custom fixed update ensures a certain call count per second. You can make a method to run 10000 times per second or just once every 10 seconds.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera ignoring LOD! 0 Answers

Low FPS on Simple geometry? 4 Answers

Unity 2017 frame rate capped? 2 Answers

Game Freezes upon successive loads 0 Answers

HDRP Reflection probes cause terrible framerate 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges