Repeatability: can you get the same outcome every time the game runs?

I’m using Unity to do operational analysis…so I need the game to play out the same for given input every time it runs.

I’ve managed to do this by having one script that listens for MonoBehaviour.FixedUpdate, and calls my own game loop…so I can control which order the GameObjects do their updating (instead of the MonoBehaviour everything-at-once not-repeatable randomisation). All repeatable now.

I can’t easily escape MonoBehaviour if I use the built-in NavMeshAgent stuff. If I try to control it so it only navigates during my game loop…it never moves. And letting it do its own thing is not repeatable. I need the characters to move to the same places at the same time (everything else being equal) everytime the game runs, so that I can seed the randomisation properly and have repeatable results.

So my question is: how repeatable is the A* Pathfinding behaviour ? Will an agent take the same time to find a path and move every time ? And/or is there a way can I take control of its game loop, or is the only way to use it relying on FixedUpdate?

Thanks in advance :slight_smile:

Hi

Pathfinding is asynchronous by default which will interfere with this, however you can modify the movement scripts to force the paths to complete immediately by calling path.BlockUntilCalculated().

Movement scripts use the regular Unity update loop by default, however you can update them in a separate script. See https://arongranberg.com/astar/docs/iastarai.html#MovementUpdate

If you use local avoidance you will also have to modify the RVOSimulator script a bit, but I think that should be easy.

Note that even floating point math is not necessarily repeatable across different machines, but I’m not quite sure when it does not apply (I just know this is a reason games like Starcraft 2 use only integer math in the game).

Excellent. And thanks for such a quick response.

1 Like