Search Unity

Discussion Simple DOTS Animation System

Discussion in 'Entity Component System' started by Bendzae, Dec 18, 2022.

  1. Bendzae

    Bendzae

    Joined:
    Dec 8, 2014
    Posts:
    5
    Hello everyone,

    I am working on a simple animation package for dots until the official one is there. I got it working kinda well for up to a 1000 animated characters at once but I am sure there are a lot of performance improvements I am missing. It would be incredibly helpful if someone would take the time to do some code review for the package as I am not that experienced with the dots stack yet.

    I plan to implement animation blending next. Suggestions or PR's are super welcome.

    https://github.com/Bendzae/unity-dots-animation

    Instructions for usage and samples can be found in the readme :)

     
    Tony_Max, apkdev, Occuros and 3 others like this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Hi,

    I'm the author of Kinemation, and have quite a bit of experience in this domain and the DOTS stack in general.

    Unfortunately, your repo is licensed under GPL, so I can't really look at it too closely to give any meaningful feedback. But if you have any questions, please ask!

    One thing I would suggest is elaborating more on your desired use cases and workflows, as well as any areas you wish to improve.
     
  3. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    why does a gpl license prevent you from meaningful feedback?
     
  4. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    866
    Because the GPL is cancer.
     
  5. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    Quickly tested things out but it worked well after I made some modifications, namely upgrade to transform v2.

    I'm still getting used to the new transform system myself but essentially LocalTransform replaces both translation and rotation(so LocalTransform.Position = translation.Value etc), and WorldToLocal is math.inverse of LocalToWorld.Value

    Also a simple system as for whatever reason the graphics entities are rotated wrong by unity's internal baking after switching to transform v2? An assembly reference to the Entities.Graphics is also required as
    DeformedEntity
    is annoyingly internal.

    I haven't ever made a pull request so not gonna attempt to learn github shenanigans, just pasting the system code here.

    Code (CSharp):
    1.     [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
    2.     [UpdateInGroup(typeof(PostBakingSystemGroup))]
    3.     [RequireMatchingQueriesForUpdate]
    4.     public partial class ResetSkinnedTransformBakingSystem : SystemBase
    5.     {
    6.         protected override void OnUpdate()
    7.         {
    8.             Entities
    9.                 .WithAll<DeformedEntity>()
    10.                 .ForEach((Entity entity, ref LocalTransform localTransform) =>
    11.                 {
    12.                     localTransform = LocalTransform.Identity;
    13.                 }).WithEntityQueryOptions(EntityQueryOptions.IncludeDisabledEntities | EntityQueryOptions.IncludePrefab).WithoutBurst()
    14.                 .WithStructuralChanges().Run();
    15.         }
    16.     }
     
    Bendzae likes this.
  6. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    If I learned of a new technique by reading the codebase, I would only be able to use it in a GPL-licensed codebase. Having to keep track of which "ideas" I am allowed to use or not allowed to use is a massive overhead on my personal development, and especially risky as I am building a similar technology.

    GPL can be great for standalone open-source applications. But for an asset in a commercial ecosystem like Unity, it is a legal nightmare.
     
    Lurking-Ninja, Occuros and Micz84 like this.
  7. Bendzae

    Bendzae

    Joined:
    Dec 8, 2014
    Posts:
    5
    Changed the license to MIT ;)
     
  8. Bendzae

    Bendzae

    Joined:
    Dec 8, 2014
    Posts:
    5
    Thanks I will try to migrate to v2 transforms asap. Thanks for having a look. I also encountered that rotation issue when baking with v2. I think it's a bug in the SkinnedMesh Baker. Your fix seems reasonable though, will incorporate it when I do the switch to v2.
     
  9. Bendzae

    Bendzae

    Joined:
    Dec 8, 2014
    Posts:
    5
    Wow, after having a look at your work with Kinemation I think my project is redundant. I was not aware that there already is such a fleshed out solution for animation in dots. I will give Kinemation a try and decide if I still want to roll my own solution for my game.

    As for my requirements: I really just need a simple and performant solution for skinning and bone animation (and blending). The system should also play nice with procedural animation/movement. Looks like Kinemation would work for that.
     
    DreamingImLatios likes this.
  10. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Thanks for that!

    Here are some general things I noticed that aren't specific to animation that you might want to look into further:
    1) You can specify a component type is exclusive to baking and baking systems via [BakingType] and [TemporaryBakingType] attributes.
    2) You need to add the [WorldSystemFilter(WorldsystemFilterFlags.Bakingsystem)] to make your system a real baking system.
    3) You can put a float directly in the BlobAsset struct next to your BlobArrays. If that data is constant relative to the blob asset (as it the case for Duration), then keeping it with the blob asset is generally a good idea for reducing memory bandwidth.
    4) You do not need to use NativeParallelHashMap<Entity, SomeComponentType> to do lookups between entities. There's a ComponentLookup type which does this, and is much faster. You can remove lots of jobs that way.

    Yeah. It sounds like your use case is exactly what Kinemation was designed for.

    For Transforms V1, I would agree. However, when we start talking about Transforms V2, things get a bit ugly. Transforms V2 removed the ability to represent float3 scaled bones. Scale becomes a single float. Since one of my goals targets stylized cinema, this is a pretty big deal-breaker for me. So I am writing my own transform system. But that means breaking compatibility with anything that uses Transforms V2. There is a way to make a reduced feature set work with Transforms V2, but I will need help implementing it and testing it because I can't justify spending time on a feature I will never use.

    Regardless of what direction you decide to go, I wish you the best!

    And lastly, I'm just going to link this thread here because this used to be how people found a bunch of stuff related to animation, but after the ECS forums got moved, it got left behind in the experimental land of inactivity.
    https://forum.unity.com/threads/dots-animation-options-wiki.1339196/
     
    Bendzae likes this.
  11. Bendzae

    Bendzae

    Joined:
    Dec 8, 2014
    Posts:
    5
    @DreamingImLatios Thanks a lot for your reply and hints. I already implemented some of your suggestions. I think I will continue working on this package as a lightweight alternative to Kinemation and because I feel it's a valuable learning experience. Thanks to @thelebaron 's PR there is now also support for Transform V2 so it might have value for some.

    Anyways keep up the great work with the Latios Framework and thanks for the help!
     
  12. YiboInsane

    YiboInsane

    Joined:
    Jul 22, 2019
    Posts:
    16
    Well currently for best performance is vertex animation texture with proper written code and shaders.
    Using a DrawMeshInstancedIndirect with data generated by Burst compiled Jobs, you can easily render 30K animated characters in 150FPS (with GTX3060 and AMD5600).
     
  13. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    You can do even better using BRG instead of DMII. But animation textures also have severe limitations with regards to flexibility and being able to do complex blends, IK, and ragdolls. That's where CPU-based solutions like this shine.
     
    Anthiese likes this.