Thanks for getting back to us, glad to hear you've figured it out.
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?
Since the documentation lists that MaterialPropertyBlock
is unsupported, it's rather risky to keep using MaterialPropertyBlock, as it might break in the future or on some platforms. I would at least recommend testing it on all target platforms if you should go with it.
There are no real downsides with managing your own instance Materials, once you've written the respective code. Batching should be broken anyway by either different MaterialPropertyBlocks or Material instances, so you lose nothing in this regard.
Scoppex I wonder in terms of efficiency and management (memory leaks with new materials?)?
You should not leak the material and only create it once per Skeleton and then re-use it (by having it constantly assigned via skeletonAnimation.CustomMaterialOverride[originalMaterial] = materialInstance;
).
Scoppex 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?
You can set custom materials also per slot via SkeletonRenderer.CustomSlotMaterials
.
You can check out the SkeletonRendererCustomMaterials
utility component code as a reference.
The component is also documented here:
https://esotericsoftware.com/spine-unity-utility-components#SkeletonRendererCustomMaterials