editor
[IDE] Fix Missing EditorApplication Context Reference
Solution
Unity 2017.1.x - Unity 6.3.x
Published Thu, Mar 26
IDEs often report that EditorApplication does not exist in the current context, even though your script compiles in Unity. This false positive occurs because the UnityEditor namespace is stripped during standalone builds, causing the IDE to lose reference when analyzing for non-editor platforms.
Quick-Fix
Use the UNITY_EDITOR preprocessor directive to hide editor-specific code from the IDE's build-target analysis, ensuring EditorApplication references only exist within the appropriate context.
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class ApplicationController : MonoBehaviour
{
public void Shutdown()
{
#if UNITY_EDITOR
// Use the boolean flag to stop Play Mode
EditorApplication.isPlaying = false;
#else
// Use the runtime method to close the build
Application.Quit();
#endif
}
}
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Canvas System] Duplicated UI Assets: Awake Initialization Skip[Key Press] Stop Input.GetKeyDown Double Triggers[Vector Graphics] Referencing SVG Assets via C# Scripts
Content inspired by a Unity discussion post.