I am trying to find a way to speed up / prewarm my simulation at the start of the game.
I want to make it seem as if the creatures in the game have been existing for a while before the viewer starts the game. The problem I encounter now is that everything “starts” at the beginning whereas I would like the player to encounter an already evolved ecosystem.
I’ve thought about this before too. The only way I saw is to essentially let the simulation run for a significant period of time before you load the game - setting the timescale to 10 or 100 or something, then running with a black screen until some trigger occurs (some amount of time, something happens in the game world).
If your simulation was more prescriptive you could maybe store different timepoints and load those. Or you could run a few times and find the general shape of the world after X days and generate that at the beginning instead.
Reminds me of couple of games where you could be killed during post-load “fadein” effect. Half Life 2 was one of them.
Jokes Aside…
What you’re trying to do is similar to X series “Out of sector combat” and Dwarf Fortress world generation.
In case of X series (spacesim), the universe is divided into sectors, and only sector where player is present is simulated in real time. The rest of the world is using simplified calculations which are nearly turn based (they’re fixed step based). This has side effect of combat working differently based on whether player is in the sector or not. A ship that performs poorly in real-time combat can be a monster in “Out of sector” combat, for example.
In case of dwarf fortress, after generating the world map, the game creates creatures within the world, and let them live and fight there, generating story events. This done at different speed compared to normal operation of the game.
You can read about it here: https://dwarffortresswiki.org/index.php/DF2014:World_generation
In case of unity. I believe you cannot “fast forward” physics, as the game forces calculation of physics at certain point of time. You could accelerate time by factor of 100, temporarily, but that’s pretty much it, unless you switch to custom physics implementation.
Beyond that, to “prewarm” the world you’ll need to create a set of rules comparable to dwarf fortress story generation mode for the purpose of fast-forwarding the game world.
Actually I think they added a feature for that a good while ago. Iirc it was pitched as a way to for example precalculate throwing arcs of physics based objects, so that you can visualize them in the UI.
Well, yeah you can accelerate physic simulation this way, but I’m not seeing how you could use this to precalculate grenade throw, as it will update EVERYTHING in the world. It is also possible that due to computationally expensive nature of the physics it still won’t be possible to reach speeds faster than maximum timescale.
games that do significant simulation generally do calculations outside of engine. You model the effects in pure code, and run the sim there. If you’re relying heavily on physics engine, this might not really be possible to do well.
I’m going to suggest more of a brute force approach. You could consider building a system where you actually run the simulation yourself for a period of time and then save the state. After it has run for an hour, or however long you want to run to pre-warm, you reload and do it again. Save whatever random seed you used to generate anything else in the game world with the state of everything you save. Create a custom build for doing this.
If you ran this every evening overnight on your computer, and had like 8 instances of the build running at the same time, you’d have about 1,000 different pre-warmed states saved in about 2 weeks time. Then in your actual game instead of randomly generating the world, you pull from one of these 1,000 pre-warmed states (and use the saved seed to generate anything you don’t actually need to save). It would still feel random with that many saved, and the outcome wouldn’t feel any different than your regular simulation (since you used the real simulation instead of a simplified system to get to the saved state), and you can always add more later with updates to your game.