Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 HexadimensionalerAlp · May 16, 2021 at 03:09 PM · fixedupdatetimescalesimulationspeed up

How to speed up simulation time without distorting results

I'm currently working on an AI for a small RTS. For training the AI I need to run a premade set of actions for 600 2000 times which would result in 333.3 hours of simulation. To shorten it I tried to increase Time.timeScale. For timeScale = 10 it worked just fine and the statistics I recorded showed no visible difference to timeScale 1.

 "recordingLength": 600.0029907226563,
 "fitness": 619.1399536132813,
 "militaryScore": 570,
 "actionsCount": 60,
 ...


The fitness is a combination of the military score and the total produced resources. The military score is the combat value of all produced military units. Action count is the total of executed actions within the 600 seconds of simulation.

The first 10 actions where executed at:
1.0040292739868165
1.0040292739868165
16.0040283203125
16.0040283203125
16.0040283203125
16.0040283203125
16.0040283203125
27.0040283203125
27.0040283203125
74.0040283203125

I expected the fitness, military score and action count to be nearly the same for every timeScale but that was not the case. For timeScale 50 the results where quite different:

 "recordingLength": 600.0029907226563,
 "fitness": 180.74000549316407,
 "militaryScore": 150,
 "actionsCount": 53,
 ...

Time of execution of the first 10 actions:

1.0084590911865235
1.0084590911865235
21.00845718383789
21.00845718383789
21.00845718383789
21.00845718383789
21.00845718383789
32.00845718383789
32.00845718383789
85.00845336914063

It looks like the AI is not able to execute as many actions on higher timeScale as it is on timeScale 10 or less.

There are two loops that could be responsible:

This one is located in the class that is responsible for recording executed actions, general statistics and ending the simulation after a set time.

  void FixedUpdate()
     {
         if (this.currentTime < GlobalVariables.simulationLength)
             {
                 this.currentTime += Time.fixedDeltaTime;
                 this.timer += Time.fixedDeltaTime;
 
                 if (this.timer > this.timeSteps)
                 {
                     SaveStats();                           // saves some small data
                     Debug.Log(">>> " + this.currentTime);
                     this.timer -= this.timeSteps;          // timeSteps is set to 1
                 }
             }
             else
             {
                 // Saving final stats and ending simulation
             }
     }


This FixedUpdate is located in the AI class and tries to execute as many queued actions as possible. If an action is not ready to be executed the AI waits for the tick (1 second) and tries again.

 void FixedUpdate()
 {
     this.timer += Time.fixedDeltaTime;
 
         if (this.timer > this.tickTime) // tickTime is 1
         {
             bool actionWasSuccessful;
 
             do
             {
                 actionWasSuccessful = TryExecuteNextAction();
             }
             while (actionWasSuccessful);
 
             this.timer -= this.tickTime;
         }
 }

I tried it with void Update() at first but changed to FixedUpdate to be frame-rate independent.

My idea was that the simulation runs an scaled equivalent of 600 seconds and therefore is able to act the same way if it runs 10 times or 50 times as fast as normal. Within this time the AI checks every second if it is able to execute the next actions. One thing I noticed with void Update() is that on timeScale 50 some frames take longer than 1-2 seconds to complete. Consequently the check for actions every second was passed over some times. But this should not be an issue with FixedUpdate.
I also tried setting Maximum Allowed Timestep to 100 so the frame would not be finished prematurely and the visible framerate is not important for the simulation.

It should be mentioned that the simulation is not deterministic due to the navigation and local avoidance of the workers executing the actions. But the recorded differences on the same timeScale are pretty small, the fitness varies by around 10.

Does someone know a way to speed up simulation without altering the process and results?

Thank you in advance, please tell me if some important informations are missing or something ist not comprehensible.

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

0 Replies

· Add your reply
  • Sort: 

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

118 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 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

Is it possible to tick the fixed timestep manually or increase the timescale beyond 100? 2 Answers

Speeding up the game while still making it run deterministically 0 Answers

Unity 3.5.7 - 4.2 upgrade: Changing Time.timeScale causes OnTriggerExit & OnTriggerEnter handlers to fire 1 Answer

How to prevent Navmesh Agent from overshooting destination with high Time.TimeScale? 1 Answer

moveposition() not working when slowing down the game!,rigidbody.moveposition not working when slowing down the game 0 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