When I press the continue button on my main menu a script loads in and reads a file from the disk that stores the players position. When the script is loaded the script does what it’s supposed to do and places the player in the position specified within the file.
However, after a second the player object will revert back to the position it is in the editor.
Is there something specific I have to do with the order of these things?
The most common culprit for data reverting back to an older state, or to a null/zero state, when the game starts, stops, or scripts are reloaded, is using variables that are not serializable by Unity.
When the Unity editor starts, it takes all GameObjects and serializes them, recreates them, and reapplies the serialized data. When the editor stops, the GameObjects are all cleared out and the serialized data is restored. This is to keep your game state as intended and to prevent playing the game from causing undesirable changes. Unity also does this serialize/recreate sequence if a script is reloaded during the game.
You can check to see what variables are serializable by Unity and try to stick to those value types, especially on public fields. I ran into issues with some GameObject data constantly being reset only to find that I was using a Dictionary, and that is not serializable. I ended up having to use a List that is converted to a Dictionary on Start, using one of the struct’s properties as a key.
Is there any default variables that can be set at/after loading process and somewhere on Update/FixedUpdete/LateUpdate etc. Position of your player resets to them?
Silly but there ara so many little rocks. No way wanted to injure you. Did same mistakes by myself many times, and much more time then left to find and debug…