How to use sprite swapping with Unity's bone rigging 2DAnimation?
I'm using Unity's newer bone 2DAnimation-system, and I want to swap sprites to change clothes, but I can't figure out how to copy the mesh/bone information from one sprite to the other to make sprite-swapping to work. Here's one of my tries causing an error: Video of it not working
I followed the official manual on how to do this: https://docs.unity3d.com/Packages/com.unity.2d.animation@2.2/manual/SpriteSwapIntro.html
Created a Sprite Library Asset by doing: Assets > Create > Sprite Library Asset.
Attached a Sprite Library component and Sprite Resolver component to the Clothes-sprite (that I connected to the bones).
Here's where I'm stuck. The manual now says one is supposed to copy and paste the skeleton-rigs to the new sprite get the swapping to work (manual's here: https://docs.unity3d.com/Packages/com.unity.2d.animation@3.0/manual/CopyPasteSkele.html) But I have no clue how to do that, or where the "Paste Button" is that they show in the manual. I tried pressing the sprite/gameobject in the hierarchy and "copying" it and then "pasting" it, but it only creates a copy of the sprite. I also I tried to copy the sprite-skin component and paste it, but it's not working and gives me an error "Sprite has no Bind Poses". Does anyone know how to actually get this to work, where to press and how?
Answer by HuldaGnodima · Jan 25, 2020 at 09:50 PM
I finally found a video-tutorial on how it's done, and I'm posting it here to those who find this thread in the future! (38:00 minute mark):
The tutorial video: https://youtu.be/vap04-Py9QM?t=2280
The copy/pasting is supposed to be done in the Sprite editor and it involves all the bones :)! That should get it to work. He's showing exactly how it's done in the video above.
Do you know if this allows making different animations for the different sprites, or does it only work if you are replacing a sprite for visual use only? I have different legs and arms for different animations and they use different bone structures.
That's a good question! So far when you do the sprite-swap it only works if the bones are exactly the same (from what I've understood). I don't know if they will change this in the future, but that's how it is right now (Sep 2020).
If you have other bones for your sprites that means the sprite-swap will not work (because the sprites are tied to different bones). You will probably have to make a custom solution that works for your specific setup. But I'm sure you can find a custom solution that works for you! You can always send off a question on Unity's 2Danimation forum here: https://forum.unity.com/threads/2d-animation-is-out-of-preview-for-2019-3.818724/page-5
Good luck!
You can use 1 asset library for multiple sprites, just make good named categories
I'm getting error :(
ArgumentException: An item with the same key has already been added. Key: LegBehind1 System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at :0) System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at :0) UnityEditor.U2D.Animation.CopyTool+NewBonesStore.MapAllExistingBones () (at Library/PackageCache/com.unity.2d.animation@5.0.5/Editor/SkinningModule/CopyTool.cs:44) UnityEditor.U2D.Animation.CopyTool.OnPasteActivated (System.Boolean bone, System.Boolean mesh, System.Boolean flipX, System.Boolean flipY) (at Library/PackageCache/com.unity.2d.animation@5.0.5/Editor/SkinningModule/CopyTool.cs:328) UnityEditor.U2D.Animation.CopyToolView.OnPasteActivated (System.Boolean bone, System.Boolean mesh, System.Boolean flipX, System.Boolean flipY) (at Library/PackageCache/com.unity.2d.animation@5.0.5/Editor/SkinningModule/CopyTool.cs:658) UnityEditor.U2D.Animation.PastePanel.OnPasteActivated () (at Library/PackageCache/com.unity.2d.animation@5.0.5/Editor/SkinningModule/UI/PastePanel.cs:66) UnityEngine.UIElements.Clickable.Invoke (UnityEngine.UIElements.EventBase evt) (at :0) UnityEngine.UIElements.Clickable.ProcessUpEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.Vector2 localPosition, System.Int32 pointerId) (at :0) UnityEngine.UIElements.Clickable.OnMouseUp (UnityEngine.UIElements.MouseUpEvent evt) (at :0) UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) (at :0) UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt) (at :0) UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at :0) UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at :0) UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at :0) UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at :0) UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at :0) UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at :0) UnityEngine.UIElements.EventDispatcher.OpenGate () (at :0)
Fix: I found the solution!! My error was related to Unity 2D Sprite Editor. In Visibility layer, there shouldn't be integers, I changed Arm1 to ArmA for example. it fixed the problem but now another problem occured. Your animations become corrupted, you should re-assign the bones. And maybe, hard edit on .anim file editing via Notepad++, Atom etc... CTRL+F and find and change all names. (FrontArm1 to FrontArmA)