In our project we have some prefabs we load from a streaming asset bundle. It recently started loading corrupt sprites in the editor (not a build).
If the prefab is dragged into the scene it works and looks fine.
If its loaded from the streaming assets bundle its corrupted.
I tried deleting and rebuilding my streaming assets as well as the library but its still coming out corrupted. I also reset my graphics shaders in the project settings
Is there anything else you can suggest that might be causing this?
Note that even more elements than just the background get distorted.There are child text objects that appear when the image is scaled up and they too get distorted.
This issue also started happening on everyones computer so its not a local issue (e.g. not a library or asset bundle recreation bug).
Here is my Asset Bundle Manager which creates asset bundles for my types of objects my ScriptableObjects and my Prefabs
{
private static AssetBundle _scriptableObjectsBundle;
private static AssetBundle _prefabsBundle;
public static T LoadScriptableObject<T>(string assetName) where T : ScriptableObject
{
if (_scriptableObjectsBundle == null)
{
AssetBundle.UnloadAllAssetBundles(true); // Required for editor editing which loads this (or you get a duplicate asset bundle load error)
_scriptableObjectsBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/scriptableobjects");
if (_scriptableObjectsBundle == null)
{
Debug.Log("Failed to load 'scriptableobjects' AssetBundle!");
return null;
}
}
if (!_scriptableObjectsBundle.Contains(assetName))
{
Debug.LogError("scriptableobjects asset bundle does not contain: " + assetName);
}
return _scriptableObjectsBundle.LoadAsset<T>(assetName);
}
/// <summary>
/// Loads the base prefab. Don't use this to edit objects, other objects must use this objects clone via the Prefabs class.
/// </summary>
/// <param name="assetName"></param>
/// <returns></returns>
public static GameObject LoadBasePrefab(string assetName)
{
if (_prefabsBundle == null)
{
_prefabsBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/prefabs");
if (_prefabsBundle == null)
{
Debug.Log("Failed to load 'prefabs' AssetBundle!");
return null;
}
}
if (!_prefabsBundle.Contains(assetName))
{
Debug.LogError("prefabs asset bundle does not contain: " + assetName);
}
GameObject baseGameObject = _prefabsBundle.LoadAsset<GameObject>(assetName);
return baseGameObject;
}
}
And then I have a Prefabs class which exclusively handles instantiating prefab copies (because my scriptableobjects are just read data I read from a map). Here is the relevant loading code:
public static GameObject LoadPrefab(T_Prefabs type)
{
if (_MAP == null)
{
init();
}
if (!_MAP.ContainsKey(type) || _MAP[type] == null)
{
Debug.LogError("Missing prefab type: " + type + " did you add the 'prefabs' asset tag!?");
}
GameObject obj = Object.Instantiate(MAP[type]);
if (obj.GetComponent<S_SerializedMonoBehaviour>())
{
obj.GetComponent<S_SerializedMonoBehaviour>().ResetState();
}
return obj;
}