I am making a game with multiple scenes and in one of them, there is more than one place the player can enter the scene from. To handle this I have some code that checks the door the player came in from and sets the player’s position to the door that they should enter from because of that. This is done with a list variable of all the spawn points in that level and an int variable that chooses the index of that list to move the player to. It looks like this:
player.transform.position = spawnPoints[LevelManagment.doorIndex].position;
This is run in an awake function.
In the editor, it works semi-consistently. Every now and then it seems to completely bypass this code and put the player where they start in the editor. One trick I have found while working in the editor is to simply reload the scene, click on a new scene and come back, and that gets it working. However, no matter what I do I can’t get this to work in the built version of the game. It still works half the time, but much more often keeps the player at their original start point with no error message in the console.
I am aware of issues with the order scripts are executed in unity and have messed around with the level management, putting it before the other scripts and after them but neither worked.
I also tried writing it as:
spawnPoint = spawnPoints[LevelManagment.doorIndex].position;
player.transform.position = spawnPoint;
This should do anything in theory but idk, I am really lost, any help is appreciated.
EDIT: I solved it, for anyone else facing this issue it is solved in this discussion: