Skip to content

Commit f7a5d08

Browse files
committed
* Double-check for possible nulls when reloading.
* Keep refreshing until no additional scripts get picked up.
1 parent d54d186 commit f7a5d08

1 file changed

Lines changed: 51 additions & 35 deletions

File tree

Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
257257

258258
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets1)
259259
{
260-
if (!_programAssetCache.Contains(fallbackAsset))
260+
if (_programAssetCache != null && fallbackAsset != null && !_programAssetCache.Contains(fallbackAsset))
261261
{
262262
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken");
263263
neededFallback = true;
@@ -271,7 +271,7 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
271271
var fallbackAssets2 = AssetDatabase.FindAssets($"t:{nameof(UdonProgramAsset)}").Select(e => AssetDatabase.LoadAssetAtPath<UdonProgramAsset>(AssetDatabase.GUIDToAssetPath(e))).OfType<UdonSharpProgramAsset>();
272272
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets2)
273273
{
274-
if (!_programAssetCache.Contains(fallbackAsset))
274+
if (_programAssetCache != null && fallbackAsset != null && !_programAssetCache.Contains(fallbackAsset))
275275
{
276276
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken pass 2");
277277
neededFallback = true;
@@ -300,39 +300,55 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
300300
return (UdonSharpProgramAsset[])_programAssetCache.Clone();
301301
}
302302

303-
[MenuItem("Window/Udon Sharp/Refresh All UdonSharp Assets")]
304-
static public void UdonSharpCheckAbsent()
305-
{
306-
Debug.Log( "Checking Absent" );
307-
308-
string[] udonSharpDataAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}");
309-
string[] udonSharpNames = new string[udonSharpDataAssets.Length];
310-
Debug.Log( $"Found {udonSharpDataAssets.Length} assets." );
311-
312-
_programAssetCache = new UdonSharpProgramAsset[udonSharpDataAssets.Length];
313-
314-
for (int i = 0; i < _programAssetCache.Length; ++i)
315-
{
316-
udonSharpDataAssets[i] = AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]);
317-
}
318-
319-
foreach(string s in AssetDatabase.GetAllAssetPaths() )
320-
{
321-
if(!udonSharpDataAssets.Contains(s))
322-
{
323-
Type t = AssetDatabase.GetMainAssetTypeAtPath(s);
324-
if (t != null && t.FullName == "UdonSharp.UdonSharpProgramAsset")
325-
{
326-
Debug.Log( $"Trying to recover {s}" );
327-
Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(s);
328-
}
329-
}
330-
}
331-
332-
ClearProgramAssetCache();
333-
334-
GetAllUdonSharpPrograms();
335-
}
303+
[MenuItem("Window/Udon Sharp/Refresh All UdonSharp Assets")]
304+
static public void UdonSharpCheckAbsent()
305+
{
306+
Debug.Log( "Checking Absent" );
307+
308+
int cycles = -1;
309+
int lastNumAssets;
310+
int currentNumAssets;
311+
string[] udonSharpDataAssets;
312+
313+
// Loop until we stop picking up assets.
314+
do
315+
{
316+
udonSharpDataAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}");
317+
lastNumAssets = udonSharpDataAssets.Length;
318+
string[] udonSharpNames = new string[udonSharpDataAssets.Length];
319+
Debug.Log( $"Found {udonSharpDataAssets.Length} assets." );
320+
321+
_programAssetCache = new UdonSharpProgramAsset[udonSharpDataAssets.Length];
322+
323+
for (int i = 0; i < _programAssetCache.Length; ++i)
324+
{
325+
udonSharpDataAssets[i] = AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]);
326+
}
327+
328+
foreach(string s in AssetDatabase.GetAllAssetPaths() )
329+
{
330+
if(!udonSharpDataAssets.Contains(s))
331+
{
332+
Type t = AssetDatabase.GetMainAssetTypeAtPath(s);
333+
if (t != null && t.FullName == "UdonSharp.UdonSharpProgramAsset")
334+
{
335+
Debug.Log( $"Trying to recover {s}" );
336+
Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(s);
337+
}
338+
}
339+
}
340+
341+
ClearProgramAssetCache();
342+
343+
GetAllUdonSharpPrograms();
344+
345+
currentNumAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}").Length;
346+
Debug.Log( $"Checking to see if we need to re-run. Last: {lastNumAssets}, This: {currentNumAssets}" );
347+
cycles++;
348+
} while( lastNumAssets != currentNumAssets );
349+
350+
Debug.Log( $"Completed {cycles} refresh cycles, found {lastNumAssets} assets." );
351+
}
336352

337353
[PublicAPI]
338354
public static bool AnyUdonSharpScriptHasError()

0 commit comments

Comments
 (0)