JuiceTin

Hello, I have a complex skeleton that uses MultipleCanvasRenderer to display in Canvas.

However it seems to be using a default material and not the ones assigned in the SkeletonData



He uses 4 different materials for clothing/weapons, but there's only 1 material slot available, and changing any of the sub Renderers don't do anything.

How can I properly set the 4 materials?

Thanks
JuiceTin
  • Postovi: 13

Misaki

Sorry for the late reply, but our Unity wizard Harri is currently on vacation and will reply next week.
Avatar
Misaki

Misaki
  • Postovi: 556

JuiceTin

Bummer, didn't think it would be too uncommon of a scenario.

The UI is sort of on hold until this can be resolved. Looking forward to his reply! :)
JuiceTin
  • Postovi: 13

Harald

It is not an uncommon scenario.
The UI is sort of on hold until this can be resolved. Looking forward to his reply!
Please always see the spine-unity documentation pages first:
spine-unity Runtime Documentation: Materials
spine-unity Runtime Documentation: SkeletonGraphicCustomMaterials
JuiceTin je napisao/la:However it seems to be using a default material and not the ones assigned in the SkeletonData
Yes, you cannot use normal shaders with a CanvasRenderer. Please never use a Material that does not use a Spine/SkeletonGraphic* shader at a SkeletonGraphic component. We have added explicit lines at multiple places in the spine-unity documentation now which explicitly state this:
spine-unity Runtime Documentation: Important Material Requirements
Avatar
Harald

Harri
  • Postovi: 3905

JuiceTin

I was a bit confused by the documentation, as we're porting the game over from Unreal and everything in Spine worked perfectly there.

Hopefully you can help clarify a few things in Unity:

1. Our entire game is built around the new 2D pipeline and 2D lights, thus using the 2D sprite shader. Does this mean Spine is not compatible with 2D sprite shaders either? (In addition to URP)

OR is this strictly just for UI and CanvasRenderer?

2. The shader is custom made with RGBA masks, etc. Using MaterialPropertyBlocks to change the data.
(Note: There are thousands of weapons/parts/etc, thus changing textures on the materials, can't use normal atlas/skin setup)

Is it possible to somehow make my custom shader use the same properties as Spine/SkeletonGraphic so it works?
(Wondering the purpose of MaterialPropertyBlock if we're forced to use spine's shaders)

(P.s. my bad, missed the CustomMatOverrides section, didn't have to do that in Unreal)

Thanks!
JuiceTin
  • Postovi: 13

Harald

JuiceTin je napisao/la:1. Our entire game is built around the new 2D pipeline and 2D lights, thus using the 2D sprite shader. Does this mean Spine is not compatible with 2D sprite shaders either? (In addition to URP)
(Note: Seems to work perfectly fine in editor)
Here I do not understand what you mean by "In addition to URP", could you please clarify? I assume you mean you are using URP with the 2D Renderer pipeline, is this correct? The line "thus using the 2D sprite shader" is also very ambiguous, could you please provide the full shader name such as Universal Render Pipeline/2D/Spine/Sprite?

In general I did not say Spine is incompatible with anything per se, but you need to use the suitable shaders with the respective components and pipelines. Normal Unity rules apply here, the shader has to fit the application.

  • HDRP is the only pipeline that is currently not supported.
  • When using a CanvasRenderer, you need to use UI CanvasRenderer shaders, such as Spine/SkeletonGraphic. You can also use other CanvasRenderer compatible shaders, but Spine/Skeleton or Universal Render Pipeline/* are not compatible with a CanvasRenderer.
  • When using URP with a 2D Renderer (using 2D lights, etc.) then you need to use URP 2D shaders, such as Universal Render Pipeline/2D/Spine/Sprite.
  • When using URP with a normal (3D) renderer, then you need to use URP 3D shaders, such as Universal Render Pipeline/Spine/Sprite.
  • When not using URP and the component is not a SkeletonGraphic component, use normal shaders that don't start with Universal Render Pipeline/ and are not Spine/SkeletonGraphic shaders. So any other shader of the spine-unity unitypackage.

See these documentation sections:
spine-unity Runtime Documentation: Shaders
spine-unity Runtime Documentation: URP Shaders Extension UPM Package

You can also use non-Spine shaders, you just need to make sure to use UI CanvasRenderer compatible shaders at a CanvasRenderer, which is used by SkeletonGraphic since it's a UI component. And you either (a) need to make sure that your shader handles premultiplied alpha (PMA) accordingly, or (b) not use PMA at the atlas texture and the SkeletonRenderer or SkeletonGraphic component.
OR is this strictly just for UI and CanvasRenderer?
What is stricly for UI and CanvasRenderer, what do you mean by "this"? In general please always be as precise as possible to save the back and forth of posting questions and answers.
2. The shader is custom made with RGBA masks, etc. Using MaterialPropertyBlocks to change the data.
(Note: There are thousands of weapons/parts/etc, thus changing textures on the materials, can't use normal atlas/skin setup)
Using MaterialPropertyBlocks is a valid approach (also documented here on the spine-unity docs pages). Note that spine-unity also offers multiple means to repack skins at runtime, just in case this is interesting for future projects.
Is it possible to somehow make my custom shader use the same properties as Spine/SkeletonGraphic so it works?
Of course that's possible, see this documentation section for additional info. When using a SkeletonGraphic component you should however start with a UI CanvasRenderer compatible shader.

Are you sure that you want to use SkeletonGraphic in the first place? It all sounds a bit as if you want to use a normal non-UI component for rendering. Then you should be using the SkeletonAnimation component instead and use e.g. a URP 2D shader and material.
(Wondering the purpose of MaterialPropertyBlock if we're forced to use spine's shaders)
I'm afraid I don't fully understand this sentence. You are not forced to use Spine shaders, you can also use other suitable shaders. Also, MaterialPropertyBlock just overrides parameters at the Material instance at a Renderer, no matter which shader you're using.
Avatar
Harald

Harri
  • Postovi: 3905

JuiceTin

Wow, incredible post thankyou, answered all my questions and more!

Just have 1 more that I can't seem to find if you don't mind. I attached a SkelGraphicCustomMaterial to the CanvasRenderer which allowed my to use my custom mats. Only problem is I can't seem to figure out how to access their properties since MaterialPropertyBlock does not exist.



Would I need to manually change the material properties for each sub renderer, or is there an easier way?

Thanks!
JuiceTin
  • Postovi: 13

Harald

JuiceTin je napisao/la:Wow, incredible post thankyou, answered all my questions and more!
Glad it helped, thanks for your kind words :).
JuiceTin je napisao/la:Would I need to manually change the material properties for each sub renderer, or is there an easier way?
I would not recommend modifying properties per submesh renderer, as the order and number of submeshes might change during an animation (e.g. by showing or hiding attachments). So unless you modify all submesh renderer Materials in the same way, you don't know which submesh is which when you want to modify e.g. only the additive Material but leave normal Materials unchanged.

If I understand what you want to do correctly, I think you might want to assign Materials programmatically, instead of via using the SkeletonGraphicCustomMaterials component. This way you can control what goes in and have references to each Material, which you can then modify according to your needs. Please see the SkeletonGraphicCustomMaterials documentation section on how to assign the Materials programmatically.
Avatar
Harald

Harri
  • Postovi: 3905


Natrag na Unity