Are physics settings different in builds vs the editor?
I have a replay system that records and replays user input. The input is recorded in FIXEDUPDATE and is passed through the replay system before use (so that the value used live is always the value that was recorded).
This creates completely deterministic replays. I can run the game in the editor, trigger the replay, and the exact same thing will happen every time. There is only one moving object in the scene.
However, when I generate a PC build of the game, the replay does not reproduce the same outcome - but it DOES always produce the SAME wrong outcome - still deterministic, just not the same as in the editor.
Are there any physics settings I should be looking for that might change when a game is built?
Thanks.
EDIT: Having realised that script execution order might be a factor, I changed all the fixedupdate functions in my object's components to 'ForceFixedUpdate()' and called them in a fixed order from a single component on the vehicle.
This did prove script execution order can cause problems, because the old replays no longer work properly.
However, replays generated in the editor (which work perfectly when replayed in the editor) STILL don't produce the same outcome in a build.
What else could I be missing?
Also, the behaviour is different on PC and $$anonymous$$ac. PC build replays only play correctly on other PCs, and $$anonymous$$ac build replays only play back correctly on other $$anonymous$$acs.
Answer by Edy · Oct 15, 2020 at 09:44 AM
Be aware that Physics in Unity are not deterministic, and different platforms will likely produce subtle differences that are noticeable in cases like yours. Editor and builds may be considered different platforms in this case.
I also have replays in my project. In order to replay exact sequences in all platforms I record not only the user input, but also the position and rotation of the rigidbody in each FixedUpdate. When playing the replay I make the Rigidbody kinematic and apply both the user input (so additional scripts keep reacting as expected) and the pose via MovePosition and MoveRotation.
Be aware that Physics in Unity are not deter$$anonymous$$istic
Unless they explicitly incorporate randomness, they almost certainly are. Like I said: it's not that the replays are randomly different each time. They always play out correctly on the same platform as they were generated (PC build, PC editor, $$anonymous$$ac build, $$anonymous$$ac editor), and they always play out in the exact same wrong way when viewed on each another platform.
I think what gives the impression of non-deter$$anonymous$$ism is how easy it is to accidentally influence the physics from Update() rather than FixedUpdate(). For instance, while I was working on this system, I absent-$$anonymous$$dedly decremented the fuel in the tank - in FixedUpdate - based on an engine RP$$anonymous$$ value that was calculated in Update. The tiny, tiny variance in the weight of the car was enough to catastrophically throw off the replay by the end of the first corner.