Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Unity 2D Animation 7.0 released for Unity 2021.2

Discussion in '2D' started by rustum, Oct 25, 2021.

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    164
    2D Animation 7.0 released for Unity 2021.2
    2D Animation Skinning Editor.png
    We are happy to announce that 2D Animation 7.0 is now available with Unity 2021.2. The focus of this version is on improving the user experience with the Skinning Editor.

    What’s new?
    • Introduced a Sprite Influence tool that displays which Sprites are influenced by a selected Bone.
    • Added a color picker to the Visibility panel to easily modify bone colours.
    • The associated keyboard shortcut is now displayed in a tooltip when hovering over a Skinning Editor tool.
    See the full changelog here.

    About 2D Animation
    The 2D Animation package adds tooling for rigging a sprite for skeletal animation. This package includes a Skinning Editor module in the Sprite Editor window for creating and editing bones, manual & automatic mesh tessellation as well as skin weights generation and painting. The Sprite Skin runtime component ties this all together to drive sprite deformation.

    This also includes support for Multiple Sprite Single Character rigging workflows through 2D PSD Importer Package.

    Getting Started
    1. Install the latest Unity 2021.2
    2. Start a new project with the 2D or 2D URP Template
    You can confirm that the 2D Animation 7.0 package is installed by opening Package Manager (Window > Package Manager) and selecting the Packages: In Project from the dropdown.
    In Project.png

    You should see a verified version of 2D Animation in your project.
    2D Animation.png

    Optional Performance Boost

    When animating your characters, you can improve the performance of the animated Sprite’s deformation at runtime by installing both the Burst and Collections package from the Package Manager. You can read more about it here.

    What can you do?
    Try it out and let us know what you think of the package. We want to know what works as expected, what doesn’t and what is missing.
     
    ImranFarid, PutridEx, kyuskoj and 4 others like this.
  2. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
    i found out that spriteskin is so bad upload_2021-11-9_2-11-34.png
     
  3. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    @afakul when asking for help, do try to give more information than just a screenshot, such as:
    - Number of Sprite Skins in the scene (I would guess you have 6?)
    - Unity version
    - 2D Animation package version

    My general suggestion here is to try out our optional performance boost, by installing the Collections and Burst packages.
     
  4. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80

    upload_2021-11-9_22-22-21.png
    i will tell the info later ,, btw


    i cannot install the burst
     
  5. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
    curently i used unity 2020
    i make a lot of spriteskins because itry to make leaf that has spring bone
    .
    ah so i have to use unity 2021 ?
     
  6. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
    [Package Manager Window] Cannot perform upm operation: Package name 'com.Unity.Collections' is invalid. [InvalidParameter].
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()



    i already used 2021.2 but i can not install the collections package
     
  7. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
    upload_2021-11-10_1-58-44.png

    does burst works with net 2.1 ? i watch the tutorial about burst and he said that the api must be 4
     
  8. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    The optional performance implementation is supported from Unity 2019.4 and onwards. You should only have to install the Burst and Collections package, no need to change any project settings.

    If you create a new 2D project in Unity 2020.3, can you install the burst and collections package following this guide?
     
  9. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80

    i dont know how to install collection in 2019 ,,there is no instal by name in package manager ,,
    i failed instaling burst in 2020

    im succass in 2021 but the scene vew seems buggy
    ( it is not like usual in previous version ,,extremly very hard to control just game object in hierrarcy ) sometimes the tools doesnot appears so have to do it in transform
    upload_2021-11-11_0-50-13.png
     
  10. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
  11. afakul

    afakul

    Joined:
    Mar 16, 2016
    Posts:
    80
    finnaly i can install it in 2020 ,thanks
     
    Ted_Wikman likes this.
  12. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hi, I'm loving the 2D animation package, thank you for making it!

    I was wondering if you could help me out with an issue I'm having. I'm doing a project that will ultimately be on WebGL. I have a character that animates with bones and skin and that all works great. What I want to do is give the user the option to upload a png to create a custom skin for the character.

    What I'm currently doing is that I have the Texture2D loaded into memory(?) and I am creating a sprite out of it with Sprite.Create() and trying to swap it into the character via SpriteLibarary.AddOverride. I get this error when I try to do this. (Note: I am testing in Unity Editor, and I'm using package version 5.0.9 because I can't upgrade to 2021)

    --------------------------------
    IndexOutOfRangeException: Index 1089302692 is out of range of '2' Length.
    Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <af218701fe324032b521ddd91f13662b>:0)
    Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <af218701fe324032b521ddd91f13662b>:0)
    Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <af218701fe324032b521ddd91f13662b>:0)
    UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (Unity.Mathematics.float4x4 rootInv, Unity.Collections.NativeSlice`1[T] vertices, Unity.Collections.NativeSlice`1[T] boneWeights, Unity.Collections.NativeArray`1[T] boneTransforms, Unity.Collections.NativeSlice`1[T] bindPoses, Unity.Collections.NativeSlice`1[T] deformed) (at Library/PackageCache/com.unity.2d.animation@5.0.9/Runtime/SpriteSkinUtility.cs:294)
    UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (UnityEngine.Sprite sprite, UnityEngine.Matrix4x4 rootInv, Unity.Collections.NativeSlice`1[T] vertices, Unity.Collections.NativeSlice`1[T] tangents, Unity.Collections.NativeSlice`1[T] boneWeights, Unity.Collections.NativeArray`1[T] boneTransforms, Unity.Collections.NativeSlice`1[T] bindPoses, Unity.Collections.NativeArray`1[T] deformableVertices) (at Library/PackageCache/com.unity.2d.animation@5.0.9/Runtime/SpriteSkinUtility.cs:265)
    UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (UnityEngine.Sprite sprite, UnityEngine.Matrix4x4 invRoot, UnityEngine.Transform[] boneTransformsArray, Unity.Collections.NativeArray`1[T] deformVertexData) (at Library/PackageCache/com.unity.2d.animation@5.0.9/Runtime/SpriteSkinUtility.cs:358)
    UnityEngine.U2D.Animation.SpriteSkin.LateUpdate () (at Library/PackageCache/com.unity.2d.animation@5.0.9/Runtime/SpriteSkin.cs:282)
    ----------------------------

    This is the code I am using below:

    public void CustomSkin()
    {
    customSprite = Sprite.Create(texture2D, new Rect(450, 50, 1150, 1600), new Vector2(0.5f, 0.5f), 100.0f);

    string referenceLabel = targetResolver.GetLabel();
    Sprite referenceSprite = spriteLibrary.GetSprite(targetCategory, referenceLabel);
    SpriteBone[] bones = referenceSprite.GetBones();
    NativeArray<Matrix4x4> poses = referenceSprite.GetBindPoses();
    customSprite.SetBones(bones);
    customSprite.SetBindPoses(poses);

    const string customLabel = "customTorso";
    spriteLibrary.AddOverride(customSprite, targetCategory, customLabel);
    targetResolver.SetCategoryAndLabel(targetCategory, customLabel);
    targetResolver.gameObject.GetComponent<SpriteRenderer>().color = Color.white;
    }


    The odd thing is that it all works if I create the sprite a different way: customSprite = Resources.Load<Sprite>(texturePath). By loading the texture as sprite from the Resources folder I get no issues. The problem with this workflow is that if I want my user to upload via WebGL, I can't save that png to resources and then load it from resources (at least my understanding is that I can't save anything into Resources folder during runtime).

    If you have any suggestions or can let me know what I am doing wrong, I would really appreciate it. Thank you!
     
  13. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Hello @GSanLob,
    First off, thank you for your kind words!

    The reason why you see this error is because when you create a Sprite using Sprite.Create, your Sprite does not generate the BoneWeight vertex information per vertex in the mesh. The BoneWeight vertex information is only created by generating a mesh inside the Skinning Editor. So when you later pass the newly generated Sprite mesh into the SpriteSkin component, it fails due to missing data.

    My general advice is that you load and use Sprites which already have had their mesh generated inside the Skinning Editor, so that each Sprite contains the data they need in order to function properly with the other 2D Animation components.

    But if you want to continue on your path you are currently on, you could also inject BoneWeight data from a reference Sprite or create your own data on the fly. I see from your code that you have a Sprite which already already have the data you are after, so you could do something like this

    Code (CSharp):
    1.  
    2. using Unity.Collections;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.U2D;
    6. using UnityEngine.U2D.Animation;
    7.  
    8. [RequireComponent(typeof(SpriteRenderer), typeof(SpriteSkin))]
    9. public class SpriteGenerator : MonoBehaviour
    10. {
    11.     public Texture2D myTexture = null;
    12.     public Sprite refSprite;
    13.    
    14.     void Update()
    15.     {
    16.         if (Input.GetKeyDown(KeyCode.K))
    17.         {
    18.             var sprite = CreateSprite();
    19.             AssignSprite(sprite);
    20.         }
    21.     }
    22.    
    23.     Sprite CreateSprite()
    24.     {
    25.         var sprite = Sprite.Create(myTexture, new Rect(0, 0, myTexture.width, myTexture.height), new Vector2(0.5f, 0.5f));
    26.  
    27.         InjectBoneWeights(sprite);
    28.        
    29.         sprite.SetBones(refSprite.GetBones());
    30.         sprite.SetBindPoses(refSprite.GetBindPoses());
    31.  
    32.         return sprite;
    33.     }
    34.  
    35.     void InjectBoneWeights(Sprite targetSprite)
    36.     {
    37.         var vertexCount = targetSprite.vertices.Length;
    38.         var blendWeightArr = new NativeArray<BoneWeight>(vertexCount, Allocator.Temp);
    39.        
    40.         var blendWeightRef = refSprite.GetVertexAttribute<BoneWeight>(VertexAttribute.BlendWeight);
    41.         for (var i = 0; i < blendWeightArr.Length; ++i)
    42.             blendWeightArr[i] = blendWeightRef[i % blendWeightRef.Length];
    43.        
    44.         targetSprite.SetVertexAttribute(VertexAttribute.BlendWeight, blendWeightArr);
    45.         blendWeightArr.Dispose();
    46.     }
    47.  
    48.     void AssignSprite(Sprite sprite)
    49.     {
    50.         var sr = gameObject.GetComponent<SpriteRenderer>();
    51.         sr.sprite = sprite;
    52.     }
    53. }
    54.  
    A word of caution though, this is not the safest operation and it will most likely be difficult to set the blend weight just right for your generated Sprite.

    Let me know how it goes!
     
  14. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hi Ted. Thank you for such a quick reply! I appreciate it.

    I tried the code you added and it worked great! I didn't get the error and the sprite now moves with the bone. The only issue I am having is how the sprite is cut out of the PNG. For example, in the image below, I tried to replace the forearm sprite with the one that is part of a custom PNG. The whole PNG got attached to the bone. I tried to modify this by changing the Rect details in Sprite.Create by calculating where the Rect cuts would be on the original PNG. However it was very hard to guess and I realized that Unity had packed the sprites in a rectangle and not the original square I had (image below). The problem is I'd love for there to be a standardized skin template that I could have, but because Unity packs the sprites in a different locations and shape, it seems hard to make it all match.

    Do you have any suggestions on how I can fix this problem? Is there a different sprite setting I need to do at import? Or something I can do with C# that could give me the data I need to input into the Rect dimensions?

    Lastly, regarding the last image, is this what you meant when you said to be cautious when blending weights - (the torso sprite is connected to two bones and when I move the child bone the torso starts to blur and stretch). Is there any way around this? Or would you suggest just keeping 1 bone per 1 sprite in order to avoid this issue?

    Thank you so much!
    Gleb

    Unity2DAnim_ErrorExplanation.png Unity2DAnim_ErrorExplanation_002.png Unity2DAnim_ErrorExplanation_003.png
     

    Attached Files:

  15. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    I'm happy you got it to work. So in your example, you have one .psb and one .png. The PSD Importer package will generate a Sprite Sheet for the texture data inside the .psb file. For the .png, there is no Sprite Sheet generation. If you want them to have the same texture layout, my suggestion is to either use only .psb or .png files. This will allow you to keep the same texture layout.

    As for Sprite Rect calculations, there is no easy way around this, apart from copying data from already existing Sprites. The alternative is to create your own algorithm where you slice and create the Sprite Rects yourself based on data you provide.

    For your final issue, it does seem like a blend issue, as you can see some stretching going on.

    My general advice would be to start small and simple, and then scale it up. Have one object per texture and make sure it works as intended. Once that works, add more complexity. This way you can more easily debug and understand what goes wrong.
     
  16. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    123
    Hi.
    Is it possible to have a Single Sprite rigged with more bones and animate the part of the sprite that is arounf the bone ?
    Or is it doable by effectors or other 2D features ?

    For example I would like to have a bone on a tree branch and animate only that part (without cutting it separately in photoshop).

    Thank you
     
  17. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Hello @VP_no1
    Yes, you do not need to cut the image into multiple pieces. Have a look at our Snake sample to see it in action.
     
    VP_no1 likes this.
  18. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    123
    Please specify a step by step workflow becasue in docuemtnation is not very straightforward.
    At the moment I did this:
    1. autogeerated geometry
    2. create the bones i needed
    3. created vertices so i encapsulate each bone like in a box
    4. now i should paint the weights

    3 -- i am not sure if this is the correct way to put the vertices
    4 -- how should i paint the weights ?
    >> do i select each bone and paint the 4 vertices that encapsulates the bone ?

    upload_2021-11-27_15-59-59.png
     
  19. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    123
    I also have the sme problem on rendering the normal sprite. It simply vanishes and I only see the bones. Why ?

    edit: for others who enter here: there must be weitght paint on everything else it wont show the sprite.
     
    Last edited: Nov 27, 2021
  20. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    123
    How to move an edge collider 2d with the bones ?
    I have the collider and an effector on a separate GO.
    I tried to have this go as child to the bone root but it doesnt move as expected.
    I think there shoudl be a way to autogenerate a collider around the bones, becsaue I do not see any other solving.
    Any ideas please ?

    later edit: i put a box collider on every single bone GO. They do move ok with every encapsulated bone.
     
    Last edited: Nov 27, 2021
  21. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    @VP_no1 for future reference, the documentation I linked earlier also contains a step by step guide on how to use the package (link). My advice to you is to go through the documentation first to see if it can help you with any of your outstanding questions. But in general it seems like you got it all working?
     
    VP_no1 likes this.
  22. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hi Ted, thank you so much for answering my questions above! I have a follow up question. I got the script to work (to switch texture/sprite during runtime). It works great for the .psb sprites. Now I am trying to use a modified script for a .png file (set to single mode) but am getting strange results - the texture is stretched and deconstructed and the bones are effecting parts they're not supposed to.

    How different are the copy processes when using .png vs .psb? I understand that png doesn't use the sprite library asset, so I deleted that part of the code, but other then that, not sure what I need to alter. Any help would be greatly appreciated! Also, is there a good resource that goes into depth about this? The Unity API/documentation doesn't really have a lot of info in it.

    Thank you! 2DRigging_PNG_BoneStretch.png
     
  23. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    I'm happy you got it to partially work. As I highlighted in my previous post, the issue you are seeing is that the Sprites from the .psb file and the Sprites from the .png file are located on different locations in the texture, so when you just copy over Sprite data from a .psb file and apply it to a .png file which is laid out differently, you will not get the same result.

    My advice to you is to either use only .pngs or .psbs, but not combine the two, since the Sprites will not be laid out the same way in the final texture.

    Also, do note that you are working with very specific limitations that most users are not limited by, this is why it can feel that the documentation we have for this particular workflow is lacking.
     
  24. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hi Ted, thanks for the quick reply. In this example I am actually working with just .pngs and all are laid out completely the same. They have the same exact size too (1024x1024). That's why I find it odd that I am getting these issues. Does this have anything to do with the issue of the version of 2D animation package / unity I'm using? I'm currently using 2020.3.17f1 and package 5.0.9.

    2DRigging_PNG_BoneStretch_Image2.png

    Totally understand that most users wont do this. But it does seem like copying and creating sprite data during runtime is a must for this package.

    The .psb code I was using previously worked great. I am trying to modify it to work with PNGs. This is what I have for the PNG version:

    Code (CSharp):
    1.  
    2. Sprite CreateCopySprite(Sprite origSprite)
    3.     {
    4.  
    5.         var newSprite = Sprite.Create(SimpleTexture2DCopy(originalTexture), origSprite.rect, new Vector2(0.5f, 0.5f));
    6.  
    7.         //Inject Bone Weights
    8.  
    9.         var vertexCount = origSprite.vertices.Length;
    10.         var blendWeightArr = new NativeArray<BoneWeight>(vertexCount, Allocator.Temp);
    11.  
    12.         var blendWeightRef = origSprite.GetVertexAttribute<BoneWeight>(VertexAttribute.BlendWeight);
    13.         for (var i = 0; i < blendWeightArr.Length; ++i)
    14.             blendWeightArr[i] = blendWeightRef[i % blendWeightRef.Length];
    15.  
    16.         newSprite.SetVertexAttribute(VertexAttribute.BlendWeight, blendWeightArr);
    17.         blendWeightArr.Dispose();
    18.  
    19.         //Copy Bones and Bind Poses
    20.         newSprite.SetBones(origSprite.GetBones());
    21.         newSprite.SetBindPoses(origSprite.GetBindPoses());
    22.  
    23.         return newSprite;
    24.  
    25.         //spriteLibrary.AddOverride(newSprite, origSprite.targetCategory, origSprite.customPartLabel);
    26.         //origSprite.targetResolver.SetCategoryAndLabel(origSprite.targetCategory, origSprite.customPartLabel);
    27.         //origSprite.targetResolver.gameObject.GetComponent<SpriteRenderer>().color = Color.white;
    28.     }
    29.  
    As far as I can understand, it seems the mesh is not copying correctly - below is the wireframe version. The original on left, and the newly created sprite (PNG single) on the right. Unfortunately, without documentation, I am completely blind as to how to make it work. Any help would be greatly appreciated. Thank you.

    2DRigging_PNG_BoneStretch_Image3.png
     
    Last edited: Dec 1, 2021
  25. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Thanks for sharing a bit more information regarding the issue. So in the code you are using, you only copy the bone weight over. We can see from the image that the meshes does not contain the same amount of vertices, so we would need to copy not only the bone weight, but all the mesh data over into the newly created Sprite. It would look something like this to perform:

    Code (CSharp):
    1.    
    2.     void CopySpriteData(Sprite targetSprite)
    3.     {
    4.         var vertexCount = refSprite.GetVertexCount();
    5.         var uvArr = new NativeArray<Vector2>(vertexCount, Allocator.Temp);
    6.         var vertexArr = new NativeArray<Vector3>(vertexCount, Allocator.Temp);
    7.         var tangentArr = new NativeArray<Vector4>(vertexCount, Allocator.Temp);
    8.         var blendWeightArr = new NativeArray<BoneWeight>(vertexCount, Allocator.Temp);
    9.      
    10.         var uvRef = refSprite.GetVertexAttribute<Vector2>(VertexAttribute.TexCoord0);
    11.         var vertexRef = refSprite.GetVertexAttribute<Vector3>(VertexAttribute.Position);
    12.         var tangentRef = refSprite.GetVertexAttribute<Vector4>(VertexAttribute.Tangent);
    13.         var blendWeightRef = refSprite.GetVertexAttribute<BoneWeight>(VertexAttribute.BlendWeight);
    14.         for (var i = 0; i < vertexCount; ++i)
    15.         {
    16.             uvArr[i] = uvRef[i];
    17.             vertexArr[i] = vertexRef[i];
    18.             tangentArr[i] = tangentRef[i];
    19.             blendWeightArr[i] = blendWeightRef[i];
    20.         }
    21.  
    22.         targetSprite.SetIndices(refSprite.GetIndices());
    23.         targetSprite.SetVertexCount(refSprite.GetVertexCount());
    24.         targetSprite.SetVertexAttribute(VertexAttribute.TexCoord0, uvArr);
    25.         targetSprite.SetVertexAttribute(VertexAttribute.Position, vertexArr);
    26.         targetSprite.SetVertexAttribute(VertexAttribute.Tangent, tangentArr);
    27.         targetSprite.SetVertexAttribute(VertexAttribute.BlendWeight, blendWeightArr);
    28.  
    29.         uvArr.Dispose();
    30.         vertexArr.Dispose();
    31.         tangentArr.Dispose();
    32.         blendWeightArr.Dispose();
    33.     }
    34.  
     
  26. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hi Ted, that worked perfectly, thank you so much for your help! It's an amazing package, looking forward to building so much with it!
     
  27. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Awesome, I'm happy you got it all working! and thank you for your kind words.
    Do share your creations later, we would love to see what is being made with the toolsets!
     
  28. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Ok I definitely will share!

    Just one last quick question. For the PNG single mode skeleton set up. Is there any way to hide a body part attached to a bone? For example if I wanted to hide the hand I would usually just turn off that Sprite Renderer or disable the game object. But since the PNG set up just has one Sprite Renderer, its either everything is on or everything is off. Is there a way go about it via script? Similarly, is there a way to change the depth of the bones at runtime via script?

    Thank you!
     
  29. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    No, you would need to slice the body parts up into different Sprites and assign them to multiple renderers, then hide the parts by disabling the renderer. Using the code above, you should be able to modify it so that it supports multiple sprites rather than only copying and pasting data from a single sprite, but I'll leave that to you as a research task.

    The depth of bones cannot be modified during runtime, it is an edit mode only setting for now.
     
  30. tharealjohn

    tharealjohn

    Joined:
    Jul 19, 2012
    Posts:
    5
    @Ted_Wikman
    I'm struggling to find a way to use this for 2D sprite sheet animations and swap for different sprites like equipment. For example, I have spritesheets that need to be layered on each other for each part of a character.

    Consider these sprite sheets as an example:
    hair-01.png character-base.png paints-01.png

    The flipbook style animation sample is similar, but that doesn't include layers for equipment, just swapping entire sprites.

    Ideally, I'd have something like a SpriteLibraryAsset for each type of sprite sheet (Body, Hair, Pants, etc). I can categorize them by their animation (MoveUp, MoveLeft, MoveDown, etc.). The label might just be the frame number.

    Then I might have a higher order SpriteLibraryCollection that can contain multiple SpriteLibraryAssets.

    In any case, I can't seem to extend this easily because SpriteLibrary and SpriteResolver make some assumptions on resolving each other and a one-to-many relationship. I think I need a many-to-many type thing.

    Additionally, recent updates changed to use SpriteKey for animation. This makes it harder to reuse animations across different categories since the key is now a hash of both category and label. Previous, I was attempting this:

    upload_2022-1-7_17-24-12.png

    This way I could use a convention for my Label (0,1,2,...) and animate it each keyframe. Then I could set the Category to my "collection" or equipment set and the right animation frame. With SpriteKey, I can't do that.

    Is there any supported way to do what I want today using this package?
     
    Last edited: Jan 7, 2022
  31. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Hello @tharealjohn
    So from what I understand, you are using flipbook as your animation style, the character is made up of multiple pieces and each pieces can be swapped out to a different style.
    Yes, this is what I would have done as well. I would create a new class which keeps a reference to all the different Sprite Library components in the hierarchy and references to the different Sprite Library Assets that can be swapped out. When you want to change the style of a certain piece, you assign the new Sprite Library Asset to the affected Sprite Library Component.

    If you then name each category according to the animation, and numerate the labels, you should be able to reuse the Animation Clips for all the different pieces.

    Did you manage to give this setup a go? and if so, does it do what you expect it to do?
     
    tharealjohn likes this.
  32. tharealjohn

    tharealjohn

    Joined:
    Jul 19, 2012
    Posts:
    5
    @Ted_Wikman

    After a lot of trial and error, I did get it to work exactly as you mentioned.

    I created multiple game objects for each "layer" of the character I wanted to have. Each of those objects has a SpriteRenderer, SpriteLibrary, and SpriteResolver.

    I swap out the SpriteLibraryAsset for each object, which corresponds to a rendering layer like base, helmet, chest, etc.

    The SpriteLibraryAssets have categories for each Animation name I support, and I enumerate out each sprite on the frame number. This means I can re-use the animations, just as you stated.

    The SpriteLibrary / Asset are a little clunky to work with and it's very tedious to setup, but so was the key frame animations with the Constant tangent changes for every keyframe.

    I'm happy it works though, thanks for the support! Something like this would make a great addition to the samples provided.
     
  33. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    279
    I'm interested in the answer to your general problem as well.

    In absence of the kind of control you seem to be looking for (I would like to have that too), I can offer you a possible solution that I think would work. We are doing something similar but on rigged 2D avatars to achieve different colored eyes, hair and clothing, and not frame by frame, but I think the general idea is the same:

    Use secondary textures for the equipable items. For example: overlay your pants in a secondary texture. You then have to control the color (and visibility if you want to make them invisible) using a material, and you would swap materials to change pant color. I wrote a Shader Forge that colors secondary textures, and you could add as many secondary textures as you need for the different equipment items.

    The big drawback I have found is that secondary textures have to be edited separately, and it would huge time saver if they could imported from layers in a PSB.
     
    tharealjohn likes this.
  34. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Great to hear that you got it all working @tharealjohn, and thanks for sharing your solution. I'll take your feedback with me to the team, so we can use it for future improvements to the 2D feature set, thanks!
     
    tharealjohn likes this.
  35. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    279
    @Ted_Wikman what is the path forward with this 2D Animation 7.0 update? I guess I don't quite understand how I should handle this:

    One of my clients is doing a game and I adivsed them at the outset that we should use 2020 LTS because we could be assured that this version would be supported into the reasonable, foreseeable future.

    Now this 7.0 update comes along but is only available for Unity 2021. This update has features what will save them a huge amount of development time but at the cost of abandoning the perceived stability that the LTS release provides. So now we are between a rock and a hard place.

    I've never gotten a clear handle on the logic of why Unity produces all these versions, and for example why this update was only made available for 2021 and later.

    So what gives and what would you recommend?
     
    EvOne likes this.
  36. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Hello @streeetwalker,
    The reason why feature updates are only implemented in our latest Unity version is because of stability. Whenever we add a new feature, there is a chance that new bugs are introduced. If you try our latest alpha version of the editor and compare it with an LTS version, you will notice that the LTS version is a lot more stable and has matured. This is why we recommend all our developers to base any project they wish to ship, on an LTS editor version.

    Regarding your client, I would say that the editor version decision depends on when they are aiming to ship. The 2021 LTS version will be released later this year, with 2D Animation 7.0. If they are aiming to release later this year and they really want to use features in Unity 2021.x, they could move over to Unity 2021.2 and prepare to later move to Unity 2021.3 (LTS) once it comes out. It really comes down to the studios own preferences and editor instability tolerance.
     
  37. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    279
    @Ted_Wikman thank you so much for your clarifications - that clears up quite a bit for me! Also, I didn't catch anywhere that a 2021 LTS version was coming.

    A couple of Questions:

    I have read that the intent with LTS versions is to provide support, updates and fixes, for 2 years. I take it that is irrespective of the actual version number? That is if Unity 2021 goes LTS at the end of 2022 year, support would continue to the end of 2024?

    Well as I am "the Studio" I know what I will tolerate as far as editor instability but I am not sure what you mean. I 'm concerned about features that I have gotten to work in one version and that change or don't work in another version. That and Build stability!

    Is this the instability you refer to, or you are talking more about editor crashes and unknown bugs?
     
  38. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    575
    Correct. If you look at Unity 2018.4 (LTS), it was launched on May 10th 2019 and the last patch version for Unity 2018.4 went out around mid September 2021.

    What I am referring to is editor crashes and unknown bugs. We only add/change features in an editors alpha/beta phase (Right now we are adding features to Unity 2022.2, which is in alpha). After alpha and beta, the only patches going into the version are bug fixes to improve stability. So my new feature in 2021.2 was shipped in the editors alpha phase, then tested by both internal and external users. After a few months, 2021.2 was officially released. By that time we had already shipped a few patches to the 2021.2 editor. A few more months passes, with even more patches applied to the editor, and then 2021.2 becomes 2021.3 LTS, which then continues to live for another 2 years, receiving bug patches as needed.

    Hopefully this explanation helps clearing our versioning system up a bit.

    Regarding your concern about features not working when moving up a Unity version. Our goal is to make this transition as smooth as possible, but we are aware that it sometimes is far from smooth. Do report bugs if you experience any breakage when upgrading your project to a newer editor (Major, minor and patch version), this will help us make the experience better.
     
unityunity