Search Unity

Official 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:
    190
    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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
    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:
    916
    @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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92

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


    i cannot install the burst
     
  5. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
    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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
    [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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
    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:
    916
    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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92

    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. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
  11. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92
    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:
    916
    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:
    916
    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:
    132
    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:
    916
    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:
    132
    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:
    132
    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:
    132
    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:
    916
    @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:
    916
    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:
    916
    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:
    916
    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:
    916
    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:
    916
    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. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    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:
    916
    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. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    @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:
    916
    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. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    @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:
    916
    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.
     
  39. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    All you need to know about: "Verified" :D

    2022-01-27_09-23-29.png 2022-01-27_09-32-53.png

    P.S. I have no idea what of the forum branches now to write
    -2D Animation was now scattered on dozens of dozens of non-interconnected threads! :oops:
     
  40. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    For 2D Animation 3.2.16 and onwards, you need up upgrade to Unity 2019.4.34f1 or newer. In this version, we fixed a crash issue that could occur when a Sprite Skin moved from outside of the frustum into the frustum of the camera. The fix required editor changes, which is why you also need the editor upgrade.

    I'll look into why the Package Manager allows you to download 2D Animation 3.2.16 with a lower Unity version.
    Thank you for the heads up.
     
    EvOne likes this.
  41. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    An update on the issue @EvOne raised yesterday; 2D Animation 3.2.16 hit a snag when it was made public and lost some of its meta data in the process, this is why the package is visible to older editor versions than intended. The Package Manager team is working on resolving this, and it should be back to normal in a few days. Once fixed, 2D Animation 3.2.16 and newer will require Unity 2019.4.34f1 or newer to be viewed in the Package Manager and installed.

    Thanks again for raising the issue.
     
    EvOne likes this.
  42. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    А long time ago in a galaxy far far away...

    I hoped that a new package of 2D Animation on the basis of the Anima2D you just purchased (then)...
    -Native AnimationPackage created by the developers of the Unity itself(!),
    this is about to make something like this very-very soon:

    2022-02-07 09_23_29-Greenshot.jpg 2022-02-07 09_24_16-Greenshot.jpg

    Just look this video on YouTube, there is all the possibilities of this Rig,
    He is amazing:


    But... The years went... and even the simple FFD is not even in the plans...

    And... Now you explained the Reason... And your whole Plan!
    At the same time, practically killing Hope... :eek::D

    -The hope that I will live long enough to live until the moment when I can see something like that in Unity with my own eyes!

    And it makes me very very sad... :oops:
    :D
     
    DragonCoder likes this.
  43. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thank you for your "story driven" feedback @EvOne.

    Like you highlighted in your post, we currently do not have any plans to implement free-form deformation (FFD) into the 2D Animation package. Our current focus is to make sure that the foundation of 2D Animation is solid, and that the user experience (both in code and in the editor) is pleasant.

    There are 3rd party plugins/assets which brings FFD into Unity, which you could try out if this is something you are looking for.

    Finally, do let us know of any concrete examples of what you are trying to accomplish that you cannot create as of right now with the toolsets provided. This allows us to understand what you are all trying to create inside Unity, so that we can improve the toolsets in future versions.
     
  44. gxchris

    gxchris

    Joined:
    Nov 28, 2020
    Posts:
    3
    I am using the skinning editor to create bones for my character but the animations required by my character vary significantly (e.g. the combat is very different from the walk, etc.). For example, the combat animation is very complicated and might need to add some hand-drawn sprites to make the animation smooth. Do you have any suggestions on how to handle this situation? Thank you!
     
  45. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    I would say that it depends on how much of the character you need to swap. For instance, we have an example in our Samples called Animated Swap where we swap out one of the hands of the character for another Sprite. We keep the rest of the character and continue to animate the bones, but with a new Sprite for one of the hands. If your structure is similar, you might want to look into this technique.

    If in your animation your character changes a bit to the point where you need a new Sprite and some new bones to affect the Sprite, you can try to enable Auto Rebind on the Sprite Skin component. This will allow the Sprite Skin to update its bone structure when the Sprite is swapped out. See this post for some more details on what to watch out for when using Auto Rebind.

    If your character completely changes in an animation and no longer fits the previous skeleton, my suggestion would be to keep multiple copies underneath a root object and enable/disable them during the animation.

    Let me know how it goes!
     
  46. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    I'm curious about the licensing state of the Triangle.NET code that was included in this package previously ( up to v6 ). V7 seems to have dropped it completely, and it seems now a UTess namespace in the 2D Common package performs the triangulation/tesselation tasks - is this assumption correct ?
    That leaves my main question: Is/was the reason for this change the somewhat unclear licensing state arround Triangle.NET ?
    If yes, where would this leave us Unity developers in regard of a potential licensing breach while using the old 2D Animation packages in our commercial projects ? Is there some (offical) word about this ?

    Just for completeness: Triangle.NET is a C# port of the following code http://www.cs.cmu.edu/~quake/triangle.html
    And on that page its states the following regarding licensing
     
    Last edited: Feb 15, 2022
  47. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    initial changelog for V7 contains the following
    So looks like at least part of my assumptions are correct
     
  48. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    569
    Hi. Apologies if this isn't the right thread to ask this, but can the imported PSBs be atlased? I can't seem to do it. I understand that internally, Unity already generates a sprite sheet per PSB file and that acts as an atlas of sorts, but there would be some benefit if we could combine multiple into a larger sprite atlas. If possible, please point me to the way? thx
     
  49. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @spacefrog,
    Yes, due to Triangle.Net’s unclear license, we opted for creating our own tessellation solution, UTess. This tessellation solution is available in Unity 2021.2 and onwards (2D Animation 7.0 and onwards).
    If you are concerned about the Triangle.Net license, our current suggestion is to upgrade your project(s) to Unity 2021.2.
    We are working on solutions for lower Unity editor versions, but do not have a timeline for this work yet.
     
  50. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @LilGames this should be possible since Unity 2019.3. Could you let us know your Unity version and how it fails?