How does Unity handle time scheduling?

I want to use Unity to build agent-based simulations that will be used in an educational setting.

  1. How does Unity do time scheduling? Is there a discrete-event time scheduler under the covers?

  2. If two objects “tie” with respect to scheduled time, how does Unity decide which object gets handled first?

Q1/2: Unity provides a random number between 0…1 (don’t know the algorithm) or an integer between two limits. The functions are aimed at randomly selecting something from an array or list, or providing a numerical value to push into another function. Certainly you could apply a curve to the 0…1 and multiply it out to get a distribution you wanted. Unity provides the ability to hand draw curves or of course you could use a mathematical function.

You can also use .NET’s random number generator.

Q3. With the main game loop Unity will run it as fast as possible (with a potential for frame syncing to limit this to a certain FPS). On every game loop all of the objects are updated. You can tell certain scripts to run before or after others and there are multiple hook in points you can use to execute code in different sections throughout the frame.

Unity provides a “time since last frame” value that you can use to provide framerate independent movement.

Physics runs in a fixed time step, so this runs one time after another to catch up with real time. It isn’t real time, it’s just catching up with it, but within that time step you can guarantee that the physics functions have incremented by the fixed step as a simulation.

Q4: As it isn’t event scheduled but game loop scheduled this doesn’t really happen (apart from my comments around being able to specify that one script executes before another.