Skip to content

Commit 366936a

Browse files
committed
feat: add OnValidate handler to sync Python tools when asset is modified
This fixes the issue with deletions in the asset, now file removals are synced
1 parent 7ba6967 commit 366936a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

MCPForUnity/Editor/Data/PythonToolsAsset.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ private string GetAssetGuid(TextAsset asset)
7474
{
7575
return UnityEditor.AssetDatabase.AssetPathToGUID(UnityEditor.AssetDatabase.GetAssetPath(asset));
7676
}
77+
78+
/// <summary>
79+
/// Called when the asset is modified in the Inspector
80+
/// Triggers sync to handle file additions/removals
81+
/// </summary>
82+
private void OnValidate()
83+
{
84+
// Cleanup stale states immediately
85+
CleanupStaleStates();
86+
87+
// Trigger sync after a delay to handle file removals
88+
// Delay ensures the asset is saved before sync runs
89+
UnityEditor.EditorApplication.delayCall += () =>
90+
{
91+
if (this != null) // Check if asset still exists
92+
{
93+
MCPForUnity.Editor.Helpers.PythonToolSyncProcessor.SyncAllTools();
94+
}
95+
};
96+
}
7797
}
7898

7999
[Serializable]

0 commit comments

Comments
 (0)