@@ -18,7 +18,11 @@ public static class SetupWindowService
1818 {
1919 private const string SETUP_COMPLETED_KEY = EditorPrefKeys . SetupCompleted ;
2020 private const string SETUP_DISMISSED_KEY = EditorPrefKeys . SetupDismissed ;
21- private static bool _hasCheckedThisSession = false ;
21+
22+ // Use SessionState to persist "checked this editor session" across domain reloads.
23+ // SessionState survives assembly reloads within the same Editor session, which prevents
24+ // the setup window from reappearing after code reloads / playmode transitions.
25+ private const string SessionCheckedKey = "MCPForUnity.SetupWindowCheckedThisEditorSession" ;
2226
2327 static SetupWindowService ( )
2428 {
@@ -35,10 +39,12 @@ static SetupWindowService()
3539 /// </summary>
3640 private static void CheckSetupNeeded ( )
3741 {
38- if ( _hasCheckedThisSession )
42+ // Ensure we only run once per Editor session (survives domain reloads).
43+ // This avoids showing the setup dialog repeatedly when scripts recompile or Play mode toggles.
44+ if ( SessionState . GetBool ( SessionCheckedKey , false ) )
3945 return ;
4046
41- _hasCheckedThisSession = true ;
47+ SessionState . SetBool ( SessionCheckedKey , true ) ;
4248
4349 try
4450 {
@@ -48,11 +54,16 @@ private static void CheckSetupNeeded()
4854 bool userOverrodeHttpUrl = EditorPrefs . HasKey ( EditorPrefKeys . HttpBaseUrl ) ;
4955
5056 // In Asset Store builds with a remote default URL (and no user override), skip the local setup wizard.
51- if ( ! userOverrodeHttpUrl
57+ if (
58+ ! userOverrodeHttpUrl
5259 && McpDistribution . Settings . skipSetupWindowWhenRemoteDefault
53- && McpDistribution . Settings . IsRemoteDefault )
60+ && McpDistribution . Settings . IsRemoteDefault
61+ )
5462 {
55- McpLog . Info ( "Skipping Setup Window because this distribution ships with a hosted MCP URL. Open Window/MCP For Unity/Setup Window if you want to configure a local runtime." , always : false ) ;
63+ McpLog . Info (
64+ "Skipping Setup Window because this distribution ships with a hosted MCP URL. Open Window/MCP For Unity/Setup Window if you want to configure a local runtime." ,
65+ always : false
66+ ) ;
5667 return ;
5768 }
5869
@@ -66,7 +77,10 @@ private static void CheckSetupNeeded()
6677 }
6778 else
6879 {
69- McpLog . Info ( "Setup Window skipped - previously completed or dismissed" , always : false ) ;
80+ McpLog . Info (
81+ "Setup Window skipped - previously completed or dismissed" ,
82+ always : false
83+ ) ;
7084 }
7185 }
7286 catch ( Exception ex )
@@ -108,6 +122,5 @@ public static void MarkSetupDismissed()
108122 EditorPrefs . SetBool ( SETUP_DISMISSED_KEY , true ) ;
109123 McpLog . Info ( "Setup marked as dismissed" ) ;
110124 }
111-
112125 }
113126}
0 commit comments