Hi. I have a problem with changing the material properties via MaterialPropertyBlock. I created my shader in the previous version of Unity and I could edit its properties by editing variables, e.g.
propertyBlock.SetFloat(diveDepthProperty, to);
targetRenderer.SetPropertyBlock(propertyBlock)
however, now after switching to Unity 6 this code does not work and my spine character disappears from the screen after making these changes. Additionally, if I do it "live" in the editor, these properties change normally on the screen. The update to Unity 6 caused this not to work. Are there already reports about this and will it be fixed?
Regards

Related Discussions
...

The issue you're experiencing with MaterialPropertyBlock in Unity 6 might be related to changes in how Unity handles material properties or potential bugs introduced in the new version. There have been reports of issues when using MaterialPropertyBlock with Unity 6, particularly when properties are not initialized correctly, leading to unexpected behavior such as disappearing characters. This has been noted in the context of using MaterialPropertyBlock with Spine animations, where uninitialized data can cause problems. It is recommended to ensure that all properties are correctly initialized and to check if there are any updates or patches available for the spine-unity runtime that might address these issues. You can also try using the SkeletonAnimation.OnMeshAndMaterialsUpdated callback to manage material updates more reliably.

@Scoppex Sorry to hear you're having troubles. Which exact version of the spine-unity runtime are you using (name of the unitypackage, also listed in Assets/Spine/version.txt, or in the Package Manager window)?

Unfortunately I don't know what known issue Spinebot is referring to. I can't remember encountering this issue so far.

Did you perhaps switch from Build-In Render Pipeline to URP when switching to Unity 6?
Do you see any errors in the console?
Are you having multiple submeshes (multiple Materials) perhaps? Then you would need to call targetRenderer.SetPropertyBlock(propertyBlock, submeshIndex).

Im currently using Package version: spine-unity-4.2-2024-12-02.unitypackage****
I thing I didnt change anything with URP. I had a unity project before and just opened it in new Unity 6 version so it converts everything automaticly.
There are no errors in the console at all. My spine object using only one material.
I was thinking there are some Unity error and was waiting for update. After update that error persist, so I have checked if I can change my material properties on basic sprite objects then its ok (its not dissapearing). Only when im changing material that is in my spine character then it dissapear from the screen. Even when Im changing values back to default then character still is invisible. First change broke everyting and then its not comming back. It happening after targetRenderer.SetPropertyBlock(propertyBlock) line. I have spend hours and cannot figure out problem :*(

@Scoppex If you can create a minimal Unity project which still shows this issue (with only the character and a script setting the custom material), you can send us a zip file to contact@esotericsoftware.com (briefly mentioning this forum thread so that we know the context). Also be sure to not include the very large generated Library directory in the package. Then we can have a look at what's going wrong.

Done. I have sended and provided link to this topic.

Was it possible to confirm what causes this error?

Thanks for sending the reproduction project. We'll get back to you here on the forum once we've figured out what's going wrong.

@Scoppex The problem seems to be that you're using MaterialPropertyBlock with Universal RP, which does not seem to be supported with Unity 6. When assigning any URP Material to a Cube (or Sprite), it does not display anything anymore when assigning an empty MaterialPropertyBlock:

propertyBlock = new MaterialPropertyBlock();
targetRenderer.GetPropertyBlock(propertyBlock);
targetRenderer.SetPropertyBlock(propertyBlock);

So I'm afraid this is unrelated to spine-unity and a new Unity 6 limitation in general.

  • Modificato

Damn, and I've already converted the project to unity 6 and I'm afraid it might not be possible to go back. Is there a workaround to make it work? Although I admit I tried assigning it to a sprite and then it worked. I only had a problem with the spine object.

  • Harald ha risposto a questo messaggio

    Scoppex Although I admit I tried assigning it to a sprite and then it worked. I only had a problem with the spine object.

    That's interesting to hear. After trying the same again I noticed that the Sprite indeed remained unchanged (did not disappear) after assigning the MaterialPropertyBlock, so remained working. I might have done something wrong with my earlier testing yesterday.

    In general the MaterialPropertyBlock documentation states though:

    Note that this is not compatible with SRP Batcher. Using this in the Universal Render Pipeline (URP), High Definition Render Pipeline (HDRP) or a custom render pipeline based on the Scriptable Render Pipeline (SRP) will likely result in a drop in performance.

    What's interesting is that it works without issues on a MeshRenderer with raptor_Material which is included in the Spine URP Shaders samples, using Spine URP 2D shaders. It seems to just occur with shader graph materials and materials using Unity's own Universal Render Pipeline/2D/Sprite-* shaders.

    It's really annoying that something that worked and that I had a project based on in Unity 5 suddenly stops working for no reason.

    Do you have any suggestions on how I could use my own shaders in Spine and Unity 6 so that I could change their parameters without the character disappearing?

    Scoppex Is there a workaround to make it work?

    Unfortunately I know of no magic settings yet to tick which make it work without issues. Disabling SRP Batching for example would have looked promising, but made your ShaderGraph materials not display already before assigning a MaterialPropertyBlock.

    As options I see:

    • 1) Writing a shader instead of using ShaderGraph.
    • 2) Finding other means to make MaterialPropertyBlock work, e.g. making disabled SRP Batcher work with your ShaderGraph material.
    • 3) Using alternatives to MaterialPropertyBlock.

    An alternative to MaterialPropertyBlock would be managing and assigning a Material instance yourself. Assigning at a SkeletonRenderer could be done via SkeletonGraphic.CustomMaterialOverride or assigning them manually in the SkeletonRenderer.OnMeshAndMaterialsUpdated callback (see the docs here).

    Maybe I would like to use the third method. However, I have a problem here. I can assign material:
    skeletonAnimation.CustomMaterialOverride[originalMaterial] = materialInstance;

    But when I try to change its values. They do not update on my character when I use:
    materialInstance.SetFloat(propertyName, value);
    or
    meshRenderer.material.SetFloat(propertyName, value);
    How do I make it update these values?

    • Harald ha risposto a questo messaggio

      By the way. Is there any way to make a shader that uses alpha transparency affect the entire character and not just its individual elements? Because when you set such a shader to e.g. 50%, it makes every element transparent and then the character looks strange and you can see how it consists of these separate elements.

      • Harald ha risposto a questo messaggio

        Scoppex However, I have a problem here. I can assign material:
        skeletonAnimation.CustomMaterialOverride[originalMaterial] = materialInstance;

        But when I try to change its values. They do not update on my character when I use:
        materialInstance.SetFloat(propertyName, value);

        We could not reproduce any issue with that, it worked on our end without any problems. Did you create the Material instance like this:

        if (materialInstance == null)
            materialInstance = new Material(replacementMaterial);

        Are you sure that the override is at all replacing the material, or whether perhaps the originalMaterial is set to the wrong material, never replacing anything?

        Okay, so due to transparency, I first have to render to the texture. I think I understand.
        But what about my previous question.
        skeletonAnimation.CustomMaterialOverride[originalMaterial] = materialInstance;
        materialInstance.SetFloat(propertyName, value);
        this doesn't seem to update the values ​​in my object. Should there be something more in the code that refreshes the character?

        • Harald ha risposto a questo messaggio

          Okay, it worked. Thanks a lot Harald! Sorry I missed your previous message. I managed to find the cause and it was setting the "mask interaction" in my object to "visible outside mask".
          Now my question is whether it would be better to set MaterialPropertyBlock and rewrite the shader from ShaderGraph or assign and use this new material?
          I wonder in terms of efficiency and management (memory leaks with new materials?)?
          In the future, I would also like to use this material to animate attachments separately. That is, for example, to animate the parameters of this shader separately for the sword, shield, etc. (e.g. it would have glowing animations when they were improved). What would be the best option?

          • Harald ha risposto a questo messaggio