Skip to content

Commit

Permalink
Add more handling for corrupt asset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Aug 6, 2021
1 parent 4154023 commit d9ec5e1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
_programAssetCache[i] = AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]));

bool neededFallback = false;
UdonSharpProgramAsset[] fallbackAssets = Resources.FindObjectsOfTypeAll<UdonSharpProgramAsset>();
var fallbackAssets1 = Resources.FindObjectsOfTypeAll<UdonProgramAsset>().OfType<UdonSharpProgramAsset>();

foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets)
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets1)
{
if (!_programAssetCache.Contains(fallbackAsset))
{
Expand All @@ -266,6 +266,22 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
}
}

if (!neededFallback)
{
var fallbackAssets2 = AssetDatabase.FindAssets($"t:{nameof(UdonProgramAsset)}").Select(e => AssetDatabase.LoadAssetAtPath<UdonProgramAsset>(AssetDatabase.GUIDToAssetPath(e))).OfType<UdonSharpProgramAsset>();
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets2)
{
if (!_programAssetCache.Contains(fallbackAsset))
{
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken pass 2");
neededFallback = true;

AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(fallbackAsset),
ImportAssetOptions.ForceUpdate);
}
}
}

if (neededFallback)
{
udonSharpDataAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}");
Expand Down

0 comments on commit d9ec5e1

Please sign in to comment.