Search Unity

Entering play-mode in script and setting variables

Discussion in 'Editor & General Support' started by themeshpotato, Oct 24, 2019.

  1. themeshpotato

    themeshpotato

    Joined:
    Apr 11, 2018
    Posts:
    55
    Okay, so I might just be tired and not thinking straight, but what I want to do is have an inspector button that automatically goes into play mode and selects the level I'm inspecting as the one I want to play. A level in our game is basically just a grid of tiles, not a scene.
    So what I thought I could do was simply calling EditorApplication.EnterPlayMode() and after that
    setup everything that should not be saved, like the level to play. I thought that since I've entered play-mode the changes would not be permanent, but what seems to happen is that the variables that I set are permanently changed like if the editor is not fully in play-mode after calling the function and therefore still thinks it should save the variables that I changed after calling it.

    Is there a way to make sure that the variables will be changed as soon as it actually enters edit-mode? Listening for the EditorApplication.playModeStateChanged event seems to get a callback too late. I want to change these variables before any Awake or Start functions are called.