Skip to content

Commit

Permalink
Workaround handling for Unity being dumb
Browse files Browse the repository at this point in the history
- Workaround handling for when Unity decides that a scriptable object is not the type it is. Which Unity claims to have fixed in 2019.4, but clearly hasn't and instead made it worse https://forum.unity.com/threads/assetdatabase-findassets-not-working.587062/
  • Loading branch information
MerlinVR committed Aug 6, 2021
1 parent 47a8bda commit 7ddf44f
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using UdonSharp.Compiler;
using UdonSharpEditor;
Expand Down Expand Up @@ -244,13 +245,39 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
{
if (_programAssetCache == null)
{
string[] udonSharpDataAssets = AssetDatabase.FindAssets($"t:{typeof(UdonSharpProgramAsset).Name}");
string[] udonSharpDataAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}");

_programAssetCache = new UdonSharpProgramAsset[udonSharpDataAssets.Length];

for (int i = 0; i < _programAssetCache.Length; ++i)
{
_programAssetCache[i] = AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]));

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

foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets)
{
if (!_programAssetCache.Contains(fallbackAsset))
{
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken");
neededFallback = true;

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

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

_programAssetCache = new UdonSharpProgramAsset[udonSharpDataAssets.Length];

for (int i = 0; i < _programAssetCache.Length; ++i)
{
_programAssetCache[i] =
AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(
AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]));
}
}
}

Expand Down

0 comments on commit 7ddf44f

Please sign in to comment.