2

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. enter image description here

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).

enter image description here

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;
    }
Aggressor
  • 13,323
  • 24
  • 103
  • 182
  • What material/shader are you using on your sprites, standard Unity or custom made ones? What happens if, after the (corrupted) sprite has been loaded, you change the material on the instantiated object (to either a different material, or a new instance of the already applied material)? There used to be (if not still are) issues with correctly applying/loading materials/shaders on objects loaded from assetbundles. – Remy Aug 14 '20 at 07:55
  • We are not using any customer shaders. I have also found if I instantiate a copy of the object in the scene, its fine. Its only if I load it from an asset bundle. If I change the material it does change back to normal (however there are children (like text) that still appear warped and distorted). The images are just sprites with no materials set on them. There is even more distorttion on things like text which just render as random dots and dashs as well so its not just 1 sprite, there are numerous images and texts rendering weird. Ill post another shot when the card is scaled up – Aggressor Aug 14 '20 at 13:34
  • Is it reproducable in a different project that just contains the code for loading/instantiating the affected assetbundles? And although unlikely to be the cause, is it possible to include your loading/instantiating code? – Remy Aug 14 '20 at 14:31
  • I am going to likely make a sample project at some point in the near future to verify this, however I will post my loading code here – Aggressor Aug 14 '20 at 14:37

0 Answers0