So… I have this script, inside an assembly set to compile in Editor only. when I remove the script, build works fine, but when I include it in the project, it crashes the whole thing! It’s as if it is going to the build, but why and how, if the assembly says it is NOT supposed to compile? And why only this script and not the other editor scripts? This is really annoying…
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
namespace EditorUtilities
{
/// <summary>
/// Automatically loads the GameManager whenever you open a new Unity scene.
/// </summary>
[InitializeOnLoad]
public static class AutoLoadGameManager
{
private const string gameManagerPath = "Assets/Scenes/GameManager.unity";
static AutoLoadGameManager() => EditorSceneManager.sceneOpened += LoadAdditiveScenes;
public static void LoadAdditiveScenes(Scene scene, OpenSceneMode mode)
{
if (scene.buildIndex != 0 && mode == OpenSceneMode.Single)
{
Scene gameManagerScene = EditorSceneManager.OpenScene(gameManagerPath, OpenSceneMode.Additive);
SceneManager.SetActiveScene(gameManagerScene);
EditorSceneManager.MoveSceneBefore(gameManagerScene, scene);
}
}
}
}