Good afternoon, I have 2 characters on stage.
They use the same 1 and the same skeleton.

But they must have 2 different materials.

The material uses a custom shader.

The inspector does not allow you to redefine the material specifically for 1 object.
And if you do this in code, then when you call the animation it will reset to the default material

I can solve the problem by creating a duplicate skeleton, but it is not a solution to have 2 copies of 1 same skeleton.

Either I'm inattentive, or I didn't find the example I needed in the documentation.
Does the skeleton support changing materials?

Related Discussions
...

To assign different materials to two characters using the same skeleton in Unity, you can use the SkeletonRenderer.CustomMaterialOverride feature. This allows you to override the material for each instance of the skeleton without duplicating the skeleton itself. Here's how you can do it:

  1. First, ensure you have a reference to the SkeletonAnimation component of each character.
  2. Use the CustomMaterialOverride dictionary to assign a new material to each character's skeleton.

Here's a code example:

// Assuming you have references to the SkeletonAnimation components
SkeletonAnimation character1SkeletonAnimation;
SkeletonAnimation character2SkeletonAnimation;

// Assign the original material if not already assigned
if (originalMaterial == null)
    originalMaterial = character1SkeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;

// Assign different materials to each character
character1SkeletonAnimation.CustomMaterialOverride[originalMaterial] = customMaterial1;
character2SkeletonAnimation.CustomMaterialOverride[originalMaterial] = customMaterial2;

This approach ensures that each character can have its own material with a custom shader without affecting the other character.

  • Misaki 님이 이 게시물을 좋아합니다..
6일 후