• RuntimesUnity
  • Loading UI prefab with Addressables material issue

I'm currently using Spine to show Live2D artwork for each character in my game inside the UI.
I'm adjusting it inside a prefab that is marked as Addressable, also marked as Addressable all spine assets needed.
The material used is a copy of the spine built-in "SkeletonGraphicDefault-CanvasGroupStraight", and also marked as addressable.

Issue happens when I load the prefab through addressable system, spine looks like not using the linked material but instead creating a copy of it without the required shader features.
Everything else is correctly being loaded from addressables; if I just reapply the material on the loaded object it works as expected, what imply that material is the only issue.

Inspector after loading with addressable:

Inspector after just re-apply the correct material:

Thank you for your time

    Related Discussions
    ...

    It seems like the issue you're encountering is related to the material not being correctly assigned when loading the prefab through the Addressable system. This can happen if the material is not properly included or referenced in the Addressable group, or if there are issues with the shader settings.

    Here are a few steps you can take to troubleshoot and potentially resolve the issue:

    1. Ensure All Assets are Addressable: Make sure that all required assets, including the .atlas.txt, .json, and the material itself, are marked as Addressable and included in the Addressable group.

    2. Check Shader Settings: Verify that the shader settings on the material are correct. The material should use the Spine/SkeletonGraphic shader, as mentioned in the context. If the material is using a different shader, it might not render correctly.

    3. Material Assignment: It seems like reapplying the material manually fixes the issue. This suggests that the material reference might be getting lost or overridden during the Addressable loading process. You can try to reassign the material in a script after loading the prefab:

         // Example script to reassign the material
         using UnityEngine;
         using UnityEngine.AddressableAssets;
         using UnityEngine.ResourceManagement.AsyncOperations;
      
         public class AddressableLoader : MonoBehaviour
         {
             public AssetReference prefabReference;
             public Material correctMaterial;
      
             void Start()
             {
                 LoadPrefab();
             }
      
             void LoadPrefab()
             {
                 prefabReference.InstantiateAsync().Completed += OnPrefabLoaded;
             }
      
             void OnPrefabLoaded(AsyncOperationHandle<GameObject> obj)
             {
                 if (obj.Status == AsyncOperationStatus.Succeeded)
                 {
                     GameObject loadedPrefab = obj.Result;
                     var skeletonGraphic = loadedPrefab.GetComponentInChildren<SkeletonGraphic>();
                     if (skeletonGraphic != null)
                     {
                         skeletonGraphic.material = correctMaterial;
                     }
                 }
             }
         }
    4. Check for Shader Variants: Ensure that the required shader variants are included in the build. Sometimes, shaders might not compile correctly if their variants are not included. You can add the shader to the Always Included Shaders list in Project Settings -> Graphics.

    5. Addressable Group Settings: Double-check the settings of your Addressable group to ensure that all dependencies are correctly included and that there are no issues with the build or load paths.

    By following these steps, you should be able to identify and resolve the issue with the material not being correctly assigned when loading the prefab through the Addressable system.

    The spinebot suggestion of auto reapplying the material after prefab loading worked!

    Thank you!

    Ennothan Issue happens when I load the prefab through addressable system, spine looks like not using the linked material but instead creating a copy of it without the required shader features.

    Glad to hear you've figured it out, thanks for letting us know!

    Likely the problem was due to different addressable groups of the SkeletonGraphic instance and the referenced material. E.g. the required material or shader being part of another not-yet-loaded addressable group. Normal Unity means of loading dependencies apply. SkeletonGraphic does not search for any materials or shaders at runtime, it only assigns the materials according to blend modes (already referenced by the component) if Multiple CanvasRenderers is enabled.

      Harald Likely the problem was due to different addressable groups of the SkeletonGraphic instance and the referenced material.

      I actually put the material on the same group to test and the same issue happened.
      But looks like the issue isn't related to spine itself, later I had the same issue with a material on a SpriteRenderer (loaded the same way, as dependency of a parent prefab)

        Ennothan I actually put the material on the same group to test and the same issue happened.

        That's surprising indeed. If you do happen to find out at a later point what the issue was, it would be interesting to hear.

        Ennothan But looks like the issue isn't related to spine itself, later I had the same issue with a material on a SpriteRenderer (loaded the same way, as dependency of a parent prefab)

        Thanks for confirming.