Skip to content

Commit 1b892dc

Browse files
committed
fix(ports): write both hashed and legacy port files; compare project paths case-insensitively to prevent sticky-port drift across reloads
1 parent 85202d4 commit 1b892dc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

UnityMcpBridge/Editor/Helpers/PortManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static int GetPortWithFallback()
3838
var storedConfig = GetStoredPortConfig();
3939
if (storedConfig != null &&
4040
storedConfig.unity_port > 0 &&
41-
storedConfig.project_path == Application.dataPath &&
41+
string.Equals(storedConfig.project_path ?? string.Empty, Application.dataPath ?? string.Empty, StringComparison.OrdinalIgnoreCase) &&
4242
IsPortAvailable(storedConfig.unity_port))
4343
{
4444
Debug.Log($"Using stored port {storedConfig.unity_port} for current project");
@@ -196,7 +196,11 @@ private static void SavePort(int port)
196196

197197
string registryFile = GetRegistryFilePath();
198198
string json = JsonConvert.SerializeObject(portConfig, Formatting.Indented);
199+
// Write to hashed, project-scoped file
199200
File.WriteAllText(registryFile, json);
201+
// Also write to legacy stable filename to avoid hash/case drift across reloads
202+
string legacy = Path.Combine(GetRegistryDirectory(), RegistryFileName);
203+
File.WriteAllText(legacy, json);
200204

201205
Debug.Log($"Saved port {port} to storage");
202206
}

0 commit comments

Comments
 (0)