Search Unity

Official 2D Animation 8.0 released for Unity 2022.1

Discussion in '2D' started by rustum, Aug 26, 2022.

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    2D Animation 8.0 released for Unity 2022.1
    2D Animation 8.png
    We are happy to announce that 2D Animation 8.0 is now available with Unity 2022.1. The focus of this version has been around improving the Sprite Swap feature by making it easier to use and more integrated in the general editor experience.

    What’s new?
    • Sprite Swap improvements
      • Streamlined Sprite Swap key framing
    • Animation quality-of-life improvements
      • Introduced Character Pivot tool in the Skinning Editor
      • Introduced an asset upgrading tool, to upgrade older Sprite Library Assets and Animation Clips to the latest version
      • Animation preview window now displays previews of Sprite deformation, Sprite Swaps and IK Solvers.
    See the full changelog here.

    About 2D Animation
    The 2D Animation package adds tooling for rigging a sprite for skeletal animation. It 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 Multi-Sprite Character rigging workflows through 2D PSD Importer Package.

    Getting Started
    1. Install the latest Unity 2022.1
    2. Start a new project with the 2D or 2D URP Template to install the latest major versions for 2D packages in 2022.1.
    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 this 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.
    And of course we want to know what you’re making with this package. Show us your creations!
     
    Ted_Wikman likes this.
  2. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    API updates
    In 2D Animation 8, we have cleaned up the public API of 2D Animation and moved a few of its methods into the internal scope. Here is an overview of the affected APIs:

    Moved from public to internal
    Namespace: Unity.U2D.Animation.Sample

    Unity.U2D.Animation.Sample.LoadSwapDLC
    Unity.U2D.Animation.Sample.RuntimeSwap
    Unity.U2D.Animation.Sample.SwapFullSkin
    Unity.U2D.Animation.Sample.SwapOptionData
    Unity.U2D.Animation.Sample.SwapPart


    Namespace: UnityEditor.U2D.IK
    UnityEditor.U2D.IK.CCDSolver2DEditor
    UnityEditor.U2D.IK.FabrikSolver2DEditor
    UnityEditor.U2D.IK.LimbSolver2DEditor


    Namespace: UnityEngine.U2D.Animation
    UnityEngine.U2D.Animation.PositionVertex
    UnityEngine.U2D.Animation.PositionTangentVertex


    Turned into an abstract class
    Namespace: UnityEditor.U2D.IK
    UnityEditor.U2D.IK.Solver2DEditor
     
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    For sprite swapping, in the basic cases, where you have a number of 'states' set up like idle/walk/run etc in the sprite library, and are using the resolver to swap between them ...... I find that the whole idea of creating an animation clip for every little animation a total overkill and too many steps. In many cases all I want is simply for the animation frames to cycle through the labels within the category, e.g. to just loop through several frames of animation while 'walking' or whatever. There should be some kind of basic frame-swapping code built-in that doesn't even use animation clips, where you can just set a) the desired framerate in fps and b) whether to play automatically perhaps. Once I've setup the library with its states, it should then be just a matter of flipping a switch to animate the thing. As soon as I use the resolver to swap states, the new animation should immediately just play. I shouldn't have to be spending time saving off multiple animation clips when all they basically do is just move through the animation frames.
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thanks for the idea, @imaginaryhuman. Are you visualizing this as an API only feature, or a mix of editor + API calls?
    Also, could you let us know the reason for why you are using Sprite Libraries for your flipbook animations in the first place?

    I'll note this down as a feature request, so we have it captured for future consideration.
     
    Last edited: Sep 2, 2022
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm talking about wisywyg editing mainly, though api in the background for those who want to go that route. I'd like to not have to get into code or extra gubbins just to do the most basic of things.

    I thought the whole purpose of the sprite libraries was to organize sprite animations per states, like an idle animation, a walking animation etc, little sequences of sprite "frames", and that the resolver is there to switch between them. Right? That seems to be what the documentation is saying unless I'm misunderstanding it.

    So I thought what I'm supposed to do is, bring in my sprite animations, set up the 'states' and group the sprite 'frames' into the states, and then switch between them as I change the state the sprite is in. Whether that be through script or visual script or whatever. Whatever is the current resolved library category/sequence should just play through its frames without having to really do much besides setting a framerate. I don't want to have to go create separate animation clips and save filenames and all that just to set that up.
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Great, thanks for diving into it a bit.

    Sprite Swap was originally created in order to help swap clothing/expressions on a deformed 2d character. The system could then inadvertently be used for flipbook animations, which we leaned into for a few versions. However, the more we look at Sprite Swap and flipbook animations, the more we notice that they do not align very well. So we are actively looking into ways to improve flipbook animations with one of the goals being, simple things should be simple.

    If you have more ideas on how we could make flipbook animations easier to create and work with, do throw them at us, we are eager to hear your ideas!
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Well in terms of animation as in motion, i would really like to see a spline in the scene view representing the ACTUAL movement path of an object in, aligned with the animation clip, and being able to edit that path in terms of positions/rotations in the scene view and have it automatically update the animation curves. Because working with "split out" x y z animation curves is totally awful in terms of intuitive visualization of where the object is actually going to go. Like, if you want to move in the x axis, you actually have to drag spline handles UP AND DOWN, which is so unnatural. And you have no clue where the object is actually going on-screen because there's no way to visualize the total spline over time. I see how anim clips are designed to allow all manner of parameters to be animated in parallel but when it comes to basic "i want my sprite to move like this along this path" it's really not right or easy. I should be able to just 'draw' freehand a spline in the scene and have the object follow it or whatever.

    In terms of what you are calling flip book animation, ie moving between a series of predefined frames and looping that around while you remain in a give 'state' of a state machine, you already have the sprite library and resolver which is what I thought you were aiming for. The only part that's sort of missing is entering a framerate and auto-play toggle or whatever. Click one button and it works. What else is there to do?

    I think unity has the functionality to drag some 'sprite sequence' into the scene view and then it asks you to save an animation clip and then it auto-animates it, although at what FPS I have no idea. But that's not really set up with any kind of state machine scenario. No good for anything but some background animation element.
     
    EvOne likes this.
  8. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    When creating frame-by-frame animation, I feel like the sprite swap system was poorly thought out. The moment you need more than some small changes, like changing from character A to character B you hit a wall.

    What if you want to allow full character customization? Female, male, hair, eyes, and clothes animations.
    Doing all of this using a single sprite library and a resolver is extremely hard (feels impossible atm) for no reason.
    The best solution I found so far is to create multiple libraries, one for each "body part."

    In addition, as imaginayhuman stated, now we need to create special clips that use the resolver values. It feels like we are working for the system rather than this system providing a better solution for an age-old issue of animating complex characters.

    It saddens me to say that after all these years, third party assets still do a better job at this common issue :(
     
    Last edited: Sep 4, 2022
    EvOne likes this.
  9. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Great feedback there. I agree that animating things in the animation window is quite clunky, with very few inspector gizmos to help you create the motion you are aiming for. I like your example of how you would like to work with a spline. I'll add this to our internal feedback system.

    Regarding flipbook animation w. Sprite Libraries as its starting point, since an Animation Clip already is a collection of assets, it feels like we are pushing users to create one collection of Sprites (Sprite Library) in order to generate a second collection of Sprites (Animation Clip). What we want to explore are ways to generate an Animation Clip with fewer steps. The "drag Sprites into a scene to create a GO and Animation Clip"-action is more in line with what we want to explore, as it requires very few steps. However, as you pointed out, customizing frame rate is missing. It is also quite a hidden action, and I think a lot of users are unaware of this one.

    @DavidNLN could you expand on why Sprite Libraries/Sprite Resolver is not helping you with full character customization?

    Yes, this is why we would like to spend more time looking into flipbook animation. It is a form of animation which is widely used, but we can for sure do better to make it easier in Unity.

    Thanks for the feedback, do keep it coming if you have more things to add.
     
  10. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    Hi!

    How can I limit FPS in the window of the 2D Animation Editor? :oops:

    Here is the screen - I do nothing, but after a few seconds of being in his window and this "nothing"
    -all the fans of my laptop begin to howl and the temperature of the processor and the GPU - crawls up!

    In general, this is the "trouble" of the Editor Unity as a whole.
    And I'm already tired of fighting it...
    But in the last beta, the editor's behavior has changed - he no longer tries to Maximum FPS just when watching an empty scene :)

    May be this is a Victory... :D
    And dear Developers have changed something and it no longer needs this shamanism with the assignment of an Application.targetFrameRate right in the Editor, not only PlayMode

    I hope :)

    But in the window of your Editor - everything is still...
    It’s very difficult to work with him like this.

    P.S. The second screenshot shows how after exiting the 2D Animation editor, the processor temperature immediately began to decrease
    2022-09-06 12_52_46-Greenshot.jpg 2022-09-06 12_53_28-Greenshot.jpg
     
    Last edited: Sep 6, 2022
  11. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @EvOne,
    We do not have a way for you to set the frame rate of the Skinning Editor. However, it would be good if you send us a bug report with this issue so we can take a closer look to see how we can improve it.
    Thanks!
     
    EvOne likes this.
  12. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Hi @Ted_Wikman, sure, first of all, let me apologize if I came off a bit too aggressive with my last comment. I was very frustrated after a day of trying to make it work.

    For reference, Here is what I ended up making: https://twitter.com/moonbellgame/status/1568244287074193414

    Unfortunately, I gave up on using the sprite library and instead wrote custom code that replaces the animations via my own "sprite library" kind of thing.
    There were several issues using it.

    First, you must create your own animation clips that modify the sprite library property. I ended up generating the clips directly from the editing software via post-process class -> this should most likely be automated if the sprites are in a sequence like so: upload_2022-9-9_23-15-10.png

    I should not have to create a clip for that. Imagine having hundreds of animations throughout the game.

    Secondly, When having a broad character creation that includes gender for example, you would most likely create two sprite libraries, and one of them would be the main one, but then, for every frame you want to replace the main one, you would need to drag and drop the correct frame to the correct slot as there is no way currently to select all frames and drop them in, again if you have a few hundreds of animations like these you will lose a finger doing this.

    But all of the above are mere inconveniences. The true break moment came to me when trying to add eyes, hair, clothes, and everything else.

    Suppose you add a new category to the sprite library, `eyes`, and add the default eyes to it, but wait, we have more than just the default eyes, so how would I add them? Add a new category? `eyes2`, `eyes3`...`eyes24`?
    But the resolver switches between libraries, not categories (which makes sense), so that won't work.
    Ok, so we need to create a library per "body part," so a sprite library for `body,` `eyes,` `hair,` etc...
    But you can only have one resolver per object, so you would need multiple resolvers, and then you would need to write some script to sync them all.

    At this point, I realized this was too much work. I sat down and wrote my own "library" and "resolver"
    The resolver sits as a top-level script like so:
    upload_2022-9-9_23-28-47.png

    It allows me to both play with it in the editor and it works at runtime it reads the clips from the `library` and makes sure to switch them at the animator when they change.
     
    PBKitty and EvOne like this.
  13. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    204
    I can see from your screenshot @DavidNLN that you are trying out the new Sprite Library Editor window from 2D Animation 9.0. We've added some automation in that window to make variant creation easier and avoid dragging sprites one by one. If you drag and drop several sprites (or a texture containing several sprites) into a category, it will go through all labels in that category and replace it with dragged sprites whenever their name match.

    There are some more rules for characters created from PSD files where you can drag and drop the file and a new category will be created for each group in the PSD and a new label for each layer. There is a documentation page coming that will show how to use it.
     
  14. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    So since it seems clear that Unity won't be restoring the ability to create sprite libraries from PSB categories like you could in 5.x, is there a way that *I* can add that capability to the sprite editor?
     
    EvOne likes this.
  15. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    I have seen developers extending the PSD Importer to generate their own sub assets, however, these solutions were quite hacky. We are looking into ways to allow developers to extend the PSD Importer, to generate additional sub assets on import, but we do not have anything concrete to share with you all at this point in time.
     
    EvOne likes this.
  16. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    I see.

    I'm also curious whether support for using skinned sprites as a sprite mask (without adding a bunch of layers and render features) is planned for some point?
     
    EvOne and DragonCoder like this.
  17. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    We currently do not have any plan for this, but do let us know how you would use it, so that I can note it down as a feature request.
     
  18. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    Well, in my case I'd like to do a particle-based effect on an animated sprite. The particles should only render on the sprite though (inverted mask). It would be a cool feature if sprite renderers with an animation could act as masks (ideally with a toggle whether to display the sprite too or not).
     
  19. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    I'd use it exactly like any other sprite being used to mask other sprites using the mask feature. It has dozens of applications, from shading to confining particles or liquids to a shape to overlaying powerups and buffs on characters. Or, as in the character I'm working on at the moment, confining eye sprites to the shape of the eye socket.



    Currently, when applying a sprite mask to a skinned sprite, the deformed vertices are not updated in the mask component, so the mask 'works' but does not deform or move with the bones(which makes it essentially useless).

    Sprite masking has been a feature for a long time, and it feels really annoying to need to create two extra layers plus adding two additional render features just to replicate it.
     
    DragonCoder and EvOne like this.
  20. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    I should have had my morning coffee before answering. In Unity 2023.1.0a5, Sprite Mask now supports deformed Sprites (link to change log). Give the alpha a spin and let us know if supports the use cases you have in mind.
     
    DragonCoder and EvOne like this.
  21. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    Ah, that might actually be a feature worth upgrading for finally, now that I've temporarily given up on sprite library entirely and rolled my own solution.
     
  22. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    It does work as needed.


    I'm having a new problem, though; when the mouse moves into the vicinity of a 2d bone gizmo, the mouse pointer vanishes. This is absolutely horrid, especially in a complex rig. Is this an intended thing, and if so is there a way to disable it? (And if not, is there a way to fix it?)



    I'm guessing it might be intended, from the way it highlights the bone in question.

    UPDATE: It does it in the sprite editor as well, which is really, really bad. I wouldn't want to attempt weight painting like this on a complex object.



    UPDATE II: I attempted to edit a bone in the sprite editor, and any attempts to type in changes in the bone edit tool throw errors:
    Code (CSharp):
    1.  
    2. ArgumentOutOfRangeException: startIndex cannot be larger than length of string.
    3. Parameter name: startIndex
    4. System.String.Substring (System.Int32 startIndex, System.Int32 length) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    5. UnityEngine.TextEditingUtilities.DeleteSelection () (at <2be549625a894e16a3ccc4eae53173b0>:0)
    6. UnityEngine.TextEditingUtilities.ReplaceSelection (System.String replace) (at <2be549625a894e16a3ccc4eae53173b0>:0)
    7. UnityEngine.TextEditingUtilities.Insert (System.Char c) (at <2be549625a894e16a3ccc4eae53173b0>:0)
    8. UnityEngine.UIElements.KeyboardTextEditorEventHandler.OnKeyDown (UnityEngine.UIElements.KeyDownEvent evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    9. UnityEngine.UIElements.KeyboardTextEditorEventHandler.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    10. UnityEngine.UIElements.TextEditingManipulator.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    11. UnityEngine.UIElements.TextElement.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    12. UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    13. UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    14. UnityEngine.UIElements.CallbackEventHandler.UnityEngine.UIElements.IEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    15. UnityEngine.UIElements.EventDispatchUtilities.HandleEventAcrossPropagationPath (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    16. UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    17. UnityEngine.UIElements.KeyboardEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    18. UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    19. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    20. UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    21. UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    22. UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <9258761a4a2f4d03a5a319a807e8b344>:0)
    23. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    24. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    25. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    26. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    27. System.Delegate.DynamicInvokeImpl (System.Object[] args) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    28. System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    29. System.Delegate.DynamicInvoke (System.Object[] args) (at <93b14d548eed4cc88574ab296ba2e94c>:0)
    30. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <2be549625a894e16a3ccc4eae53173b0>:0)
    31.  
    32.  
     
    Last edited: Sep 23, 2022
  23. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thank you for trying out the latest build, and giving us feedback!
    Could you file two separate bugs for us, one for the cursor issue you are experiencing and another one for the error you see when editing a text box?
    Once done, please share the incident numbers (IN-XXXX) so we can take a closer look and assign these to the appropriate teams.
     
  24. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45

    Ok, I'll attempt to reproduce in a less giant project then. So to be clear, the cursor thing isn't intended behavior?
     
  25. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    The cursor behaviour you are seeing is expected, but I would like to take a closer look at your use case to see if we can improve it in any way. Having the issue contained in a bug report makes it a lot easier continue our conversation and also share it with other teams.
    Thanks for your help, and do let us know if there are other issues you are seeing!
     
  26. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    Suggestion: How about switching to the thin crosshair cursor instead of disabling it?

    That is a great thing! It worked for me as well. Guess a real incentive to prepare my project for 2023, or are there plans to backport it to 2022?
     
    PBKitty likes this.
  27. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thanks for the suggestion, I'll note it down.

    I'm happy that the Sprite Mask changes worked for you, thanks for testing it out! This change will not be backported to older versions of the editor.
     
  28. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think for me the main issue is this.

    In a game of any sophistication, I'm going to have some kind of entity. Whether it be an enemy ship or character or environmental objects. These entities aren't just going to be sitting there as idle animation or just something that cycles through one set of frames. Anything with any AI of any kind is going to act and move and stuff and have states. Maybe it's idle, maybe it's walking, maybe it's attacking, maybe its in hunt mode, whatever. So now an entity becomes a whole system of states as a state machine, and within each state there is logic to be run etc. Such a sensing if the player is nearby, or detecting when to move, etc. Along with EACH of those states, there's going to be a need for an animation of some kind, what you call flipbook, where a sequence of frames is looped through while the entity is in that given state. So while the enemy spaceship is idle it floats along with some basic animation, it goes into a 'preparing to attack' mode and shows another animation, then goes into attack mode and shows another animation. This is a whole collection of states in a state machine with behavioral stuff going on, and where each state has its own animation strip ie frame sequence. And it might even be that a given state has multiple potential animations which are randomly selected as variants or chosen as an offset in some list for that particular entity.

    Now I ask myself how am I going to set that up in Unity, and honestly I haven't got a clue. It's not in any way going to be enough to drag some sprite into the scene. I need a whole system of sprites. I need a state machine. I need the states to drive which animation is chosen and played. I need playback to be handled at proper rates. I might even need different timing per-frame in order to implement the proper sense of motion that I want - it can't just loop through the frames at a fixed rate.

    This is all without even BEGINNING to mention that some people start introducing such things as skins or add-ons such as extra weapons or items attached to the player optionally, or trying to switch out the graphics for other entire sets of graphics. So how am I supposed to do that in Unity? It doesn't seem like there is anything really catering to this. If I'm supposed to use the 'animation' system as in this thread, then it seems I'm supposed to set up a sprite library with its various states and a resolver to switch the animations, and then I need an animation clip per sequence in order to set the proper timing of individual frames. And then I need some over-arching thing to tie it all together so that one "entity" can be managed as a state machine and all that. Is this the intended way to work? I mean. .... I can't see any other built-in way to do this. If I want my entities to have multiple states and multiple animations at the very least, there has to be a way to manage all of those together in one place and handle the switching between the states and which animations show and how fast etc. Some kind of entity controller. And yes I know that probably means this would all typically be done in some state machine visual scripting graph or something, but at the same time that's quite complex to set up.
     
  29. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    @imaginaryhuman
    Am a bit confused.. You are aware Unity's Animator comes with a full on state machine system, including visualization etc., right?


    Furthermore you can use "animation layers" which have weights to modify an animation clip using another (without fully transitioning to it). Neat for adding general randomness and also for example to make a character look exhausted during the usual actions due to some debuff without having to duplicate and modify every single animation clip.

    Sure for something really complex, you have to overcome challenges and think of an architecture, but universal systems just cannot please every usecase without becoming complex to use.
     
    tonytopper and PBKitty like this.
  30. suntabu

    suntabu

    Joined:
    Dec 21, 2013
    Posts:
    77
    So still no supports for UGUI skeleton animation. very disappoint.
     
  31. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    As Dragoncoder said, Unity has a full state machine for animators built in already, without the 2d animation package and the sprite package already has flipbook animation built-in. You can easily combine the two of them in much the same way you can for any 3d or 2d object.

    I will agree that Unity has a terrible problem with misnaming their packages, but in this case everything you are trying to do can be done without the 2d animation package. That's why those things aren't included in the 2d animation package. A better name would have been 2d sprite rigging or something, probably, or 2d sprite extensions perhaps.

    You can also handle flipbooks via shader- using either a script or the animator to control variables in the material. Shadergraph has a flipbook node, or you can write such a function fairly easily in a shader manually (set u offset to modulo of frame/cells across, set v to remainder of frame/cells across). This technique is best for sprite sheets with sequential frames in a grid, obviously, and also works for particles(which have their own flipbook module).

    Skins are a place where you might have some benefit from the 2d animation package, but I personally dislike the sprite resolver so I wrote my own equivalent. Your needs for that will depend a lot on your game.
     
  32. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    Would you be able to share what are the things you don't like about it?
    We will be interested to see your implementation if you are willing to share.
     
  33. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    Well, you can see my previous posts on the subject when I was complaining about it. The one-click setup using photoshop layer groups was the single thing that I really liked about the sprite resolver, and that was removed. It is obnoxious to set up, is limited to sprites, and is more focused on 'customizing characters' and similar functions rather than animation(which is what I use it for).

    My own alternative is not very well written and is dead simple, but it is very effective; just give it a pile of game objects in order and an index and it will show the matching sprite/object for whatever the index is set to.

    You can also set it to loop, if the index is above or below the array's size.

    This setup is beneficial for animating, because it reduces the need for hold keyframes(Though you can use them when appropriate), and also allows for sequences. For instance, if you have a five frame 'blink' animation, you can just keyframe the open and closed eyes and it will interpolate the inbetween frames rather than tediously setting each frame. You could use this for numerical displays, animation sequences, angle rotations, or whatever, using whatever animation curves you like. I considered adding a ping-pong option for overflow but I ended up not needing it yet.

    It also allows for non sprites to be added.

    Swapping game objects is likely less efficient than changing the sprite data, but it is much less limiting, since you can swap any elements you want with very little setup, and you can even swap entire hierarchies just as easily as sprites.

    The script is terrible, but I'm an animator and not a coder. And to reiterate, this is for use in animation, rather than character customization or skeleton sharing.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GOSwitcher : MonoBehaviour
    6. {
    7.  
    8.     public string label;
    9.  
    10.     public int index;
    11.     public bool loopOnOverflow = false;
    12.     int prev;
    13.     public GameObject[] variants;
    14.  
    15.     void Start()
    16.     {
    17.         Switch();
    18.     }
    19.  
    20.  
    21.     void Update()
    22.     {
    23.         if (prev != index){Switch();}
    24.     }
    25.  
    26.  
    27.     void OnValidate()
    28.     {
    29.         Switch();
    30.     }
    31.  
    32.     void Switch()
    33.     {
    34.         prev = index;
    35.      
    36.         if (loopOnOverflow)
    37.         {
    38.             index += variants.Length*2;
    39.             index = index % variants.Length;
    40.         }
    41.      
    42.      
    43.         for (int i = 0 ; i < variants.Length; i++)
    44.         {
    45.             if (variants[i] == variants[index]) {variants[i].SetActive(true);}
    46.             else {variants[i].SetActive(false);}
    47.         }
    48.      
    49.     }
    50.  
    51. }
     
    Last edited: Oct 10, 2022
    Leo-Yaik likes this.
  34. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    There is no way on earth I am ever going to use that monstrosity for a 2d game.
     
  35. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    I agree that that video they linked is terrible and nobody should use it ever. But mecanim is perfectly usable for 2d games, and has all those features you said you wanted.

    Of all the videos you could have used, you show one that basically undermines the concept of a state machine entirely.

    Maybe something like this one:
     
  36. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    What's happening here?:
    upload_2022-10-18_11-5-46.png

    Happens in 8.0.4.
    In 8.0.3 (with "com.unity.2d.psdimporter": "7.0.2") it's positioned properly, but this error prevents me from using that version:

    Code (CSharp):
    1. NullReferenceException: Max Size: SerializedProperty is null
    2. UnityEditor.EditorGUI.BeginPropertyInternal (UnityEngine.Rect totalPosition, UnityEngine.GUIContent label, UnityEditor.SerializedProperty property) (at <7d481861b3d34328a9633ade22dcedd6>:0)
    3. UnityEditor.EditorGUI.BeginProperty (UnityEngine.Rect totalPosition, UnityEngine.GUIContent label, UnityEditor.SerializedProperty property) (at <7d481861b3d34328a9633ade22dcedd6>:0)
    4. UnityEditor.Modules.DefaultTextureImportSettingsExtension.ShowImportSettings (UnityEditor.BaseTextureImportPlatformSettings editor) (at <7d481861b3d34328a9633ade22dcedd6>:0)
    5. UnityEditor.BaseTextureImportPlatformSettings.ShowPlatformSpecificSettings (System.Collections.Generic.List`1[T] platformSettings, System.Int32 selected) (at <7d481861b3d34328a9633ade22dcedd6>:0)
    6. UnityEditor.U2D.Common.TexturePlatformSettingsHelper.ShowPlatformSpecificSettings () (at Library/PackageCache/com.unity.2d.common@7.0.1/Editor/InternalBridge/TexturePlatformSettings/TexturePlatformSettings.cs:158)
     
    Last edited: Oct 18, 2022
  37. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @PrecisionCats could you file a bug report so we can take a closer look?
     
    MelvMay likes this.
  38. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
  39. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Hey @Ted_Wikman

    I finally had a chance to test 2D Animation 8.0.5 in Unity 2022.1 and it's crazy how much of an improvement it is (in regards to the automatic weights). I personally felt as thought the previous iteration of automatic weights in 2021/2022 wasn't really useful for anything, even as a base to start working on. It would sometimes give such chaotic results that starting from scratch was faster; that is no longer the case at all.

    It is greatly improved and definitely good enough to use in projects; however, although I wouldn't say this should be a priority, I'd like to give some feedback for the future.

    In most cases now, the automatic weights deform very nicely. However, I'm noticing that the result is not quite as nice compared to 2020 for things like limbs. Here is an example comparing 2020 to 2022:

    2020.JPG 2022.JPG

    2020 is on the left, 2022 on the right. These are two separate sprites, the upper arm and forearm. Using 2022, the sprites pinch more at the elbow area when deformed causing a less natural looking deformation compared to 2020. Some areas are nearly identical like the wrist. This is very easy to manually fix, so I wouldn't say it's a big issue, just slightly more work than in 2020 which gave near perfect results.

    I'm noticing that sometimes the smoothness of weight distribution isn't working that well in 2022. It works well in most cases, but depending on the sprite shape, it can still give poor results:

    Smooth_2020.JPG Smooth_2022.JPG

    2020 is on the left, and you can see that the deformation is much nicer looking and has much smoother weight distribution among vertices. The meshes look different because I used the automatic mesh generation from each version which gave different results (same settings), but I've done testing with identical meshes and similar issues still occur in 2022.

    This is just feedback for the future, I do greatly appreciate the work you've all put into this, and I'm looking forward to upgrading to Unity 2021 when 2D Animation 7.0.9 is available.

    Thanks!
     
    EvOne likes this.
  40. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thank you for your kind words and testing the version out!
    Would you mind sharing these files and their meta files in a DM? Then we can take a closer look at what is going on and see if we can fine tune the weight algorithm further.
     
  41. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    It seems like the biggest difference here is the lack of a vertex near the bone- this has always been a weakness of their automatic weighting. Even if you're using their mesh generation, I highly recommend placing a vertex right at the joint before auto weighting. This also tends to improve mesh deformation, since it distributes the distortion of bending joints around the center of the rotation rather than it 'bunching up.'
     
    EvOne and Unrighteouss like this.
  42. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Great tip, thanks.

    After doing some more testing, I'm actually finding bad results like the image I showed are very rare and difficult to reproduce. Bad results could also sometimes occur in 2020's iteration of automatic weights, so I think I may have jumped the gun with that feedback.

    I'll definitely be testing out your advice though.
     
    PBKitty likes this.
  43. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    Maybe options to adjust the auto-weights would be a good idea. It surely has a bunch of parameters that are currently set to fixed values.
     
    Unrighteouss likes this.
  44. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thanks for the tips, @PBKitty. To get the exact results you are after, you will have to do some touch ups/tweaks with the other tools in the Skinning Editor. But it is always good to know in which areas we can improve.

    @DragonCoder which parameters do you feel we should expose?
     
  45. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Unrighteouss likes this.
  46. PBKitty

    PBKitty

    Joined:
    Dec 23, 2021
    Posts:
    45
    I think that having an option to place a vertex at the origin of each bone that it will be finding weights for could be a good option for when it is generating both mesh and weights.
     
  47. AnaWilliam850

    AnaWilliam850

    Joined:
    Dec 23, 2022
    Posts:
    36
    Hi! that is really cool, thanks
     
  48. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    Am finally getting to use the Animation2D package more extensively and I'd like to modify a SpriteSkin via code.

    @Ted_Wikman
    Have you considered making SpriteSkin.rootBone and SpriteSkin.boneTransforms (including the length) writeable?
    Or have dedicated methods for that in case you want to explicitly warn the user to only manipulate those if they know what they are doing.

    I don't know many other things that can be set via inspector but not via code and find that's something that should be avoided.
     
  49. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @DragonCoder making SpriteSkin.rootBone and SpriteSkin.boneTransforms writeable is something we are considering, since we have seen a few of the developers wanting to set the Sprite Skins up in runtime. I cannot promise when we will enable this path, but its always good to know what changes you would like to see in the future.

    Thank you for sharing!
     
    DragonCoder likes this.
  50. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,696
    Just removing the "internal" keyword of the setter for those two properties seems to have worked flawlessly :)
    Naturally I have not done in-depth testing for edge cases and whatnot.
    Thank you for considering this.