In typical RPG game items can be represented just as sprites in inventory and also be equipped on character. I do not like idea that I have the same sprite twice: in unity as a normal sprite asset, that can be bundled into unity-atlas. And one more time as some totally different spine atlas part with different shaders etc.

Can it be managed somehow better? In ideal case I would like the following conditions to be met. Let's make it on simple example of sword.
1) I only once have my sword sprite added in game. It is just regular unity sprite and it is not part of atlas until the unity packs all sprites into build. So I can easily adjust it.
2) I can change this sprite at runtime, for example replace brozne sword with steel sword or even fire sword.
3) I still can equip my sword on spine-based character. I still can enjoy all benifits of Spine skeleton and animations. I want possible using mesh animations on this sword inside Spine.
4) Scalability: if I have 10 sword in game and I want to add 1 more, I do not need to repack all characterrs atlasses once again, possible producing 100mb changes in git only by adding a sword or even adjusting single pixel in sword sprite.

Is it possible? Or at least partly possible?

  • Misaki がこの投稿に返信しました。
    Related Discussions
    ...

    Yes, it is possible to achieve your desired workflow using Unity's SpriteAtlas and Spine's capabilities. Here’s how you can manage it:

    1. Single Sprite Management: You can use Unity's SpriteAtlas to manage your sprites. This way, you only need to add your sword sprite once as a regular Unity sprite. You can then pack these sprites into a Unity SpriteAtlas which will be used at runtime.

    2. Runtime Sprite Replacement: You can change the sprite at runtime by using Unity's SpriteAtlas and Spine's SpriteAttacher utility. This allows you to replace the bronze sword with a steel sword or any other variant dynamically.

    3. Equipping on Spine Character: You can use the SpriteAttacher utility script or the available extension methods to assign Unity sprites to Spine slots. This allows you to equip the sword on a Spine-based character and still enjoy all the benefits of Spine skeletons and animations, including mesh animations.

    4. Scalability: By using Unity's SpriteAtlas, you avoid the need to repack all character atlases whenever you add or adjust a sprite. This significantly reduces the overhead and potential large changes in your version control system.

    Here’s a step-by-step approach to implement this:

    1. Create and Manage Sprites in Unity:

      • Add your sword sprite as a regular Unity sprite.
      • Use Unity's SpriteAtlas to pack these sprites. This can be done in the Unity Editor.
    2. Assign Sprites to Spine Slots:

      • Use the SpriteAttacher utility script to assign the Unity sprite to a Spine slot. This can be done at runtime.
      • Example code to attach a sprite:
             using Spine.Unity;
             using UnityEngine;
        
             public class EquipSword : MonoBehaviour {
                 public SkeletonAnimation skeletonAnimation;
                 public Sprite swordSprite;
                 public string slotName = "weaponSlot";
        
                 void Start() {
                     var skeleton = skeletonAnimation.Skeleton;
                     var slot = skeleton.FindSlot(slotName);
                     var attachment = SpriteAttachmentLoader.NewAttachment(skeleton, slotName, swordSprite);
                     slot.Attachment = attachment;
                 }
             }
    3. Dynamic Sprite Replacement:

      • To replace the sprite at runtime, simply update the sprite reference and reassign it using the SpriteAttacher utility.
    4. Avoid Repacking Atlases:

      • By using Unity's SpriteAtlas, you avoid the need to repack atlases in Spine. This allows you to add or adjust sprites without significant changes to your project’s assets.

    For more detailed information, you can refer to the spine-unity Mix and Match documentation and the spine-unity FAQ.

    By following this approach, you can efficiently manage your sprites and integrate them with Spine animations, meeting all your conditions.

    Maltakreuz You may find that what is demonstrated in the Spine Examples/Other Examples/Mix and Match Equip sample scene is exactly what you are looking for. This scene demonstrates how to attach a new image to the skeleton using Sprites as the source image instead of the original image in the texture atlas, and how to pack the original image and the added image into a single texture at runtime. Check out the example scripts used in the scene.