Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

2D entities outside of Tiny environment

Discussion in 'Project Tiny' started by Krajca, Jan 25, 2021.

  1. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    Hi, I'm interested in the 2D game but for PC. I've tested few custom solutions, but everyone seems abandoned. Can com.unity.2d.entities be used with standard DOTS packages?
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    2d.entities is Tiny-only currently (not sure if there are plans to change that)
     
  3. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    And as far as I know, there are no plans for 2D entities in HybridRenderer, yes?
     
  4. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Yeah, never saw any mention about that neither, so I would assume that there are no plans.
     
    Krajca likes this.
  5. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    For non tiny you can attach normal sprites as hybrid components. If hybrid renderer is installed it will do it automatically, you just convert your sprite to an entity and it works. Not exactly ideal since you can't reference the sprites in jobs/burst and the automatic position syncing is a bit slow, but it's a good middle ground for now.
     
  6. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    Yeah, you are probably right. I've planned huge tilemaps, like min 1k x 1k, so I'm looking for a more performant solution I think. But for now, I'll stick to hybrid components

    It's sad that 2D games are somewhat in limbo.
     
  7. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    904
    This is correct. 2D Entities package is there to enable in editor view of DOTS authored 2D data. It is created to be used with Project Tiny.

    For 2D in Hybrid, @Sarkahn is correct that Hybrid Renderer creates references to "classic" data, such as SpriteRenderers, which can then be reached inside an ECS world. However, the data is still managed, meaning it cannot be included in bursted jobs or run in parallel.

    For future 2D work in DOTS, we are collecting feedback from devs to see what type of 2D games devs would like to create using DOTS. I am interested in knowing a bit more about your planned project @Krajca and understand a bit more what prevents you from creating this with the standard 2D toolset.
     
    NotaNaN likes this.
  8. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    I'm currently doing work for a client involving flow fields on huge maps with thousands of sprites. Just syncing the gameobject positions for the sprites takes ~4-6 ms every frame, and that's on a pretty beefy machine. Personally I would say the 2D toolset is great, but not being able to use any of it in burst or jobs prevents it from (easily) being used in projects with large scale worlds with thousands of characters on screen at once.
     
    NotaNaN likes this.
  9. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    904
    @Sarkahn, thanks for sharing! Do you have some more detailed profiling data we could take a look at? You could PM this to me if it is sensitive data.
     
  10. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    @Ted_Wikman Sure, before I started the project I created a really simple prototype to make sure it would be viable - my first hunch being that syncing the gameobject positions would be the bottleneck. I took two screenshots and attached the profiling data. I ran two tests, one with 5000 agents, one with 15000 agents. In both cases the only real "work" I'm doing in the scene (calculating velocity and setting translation) takes a fraction of a millisecond.

    These were taken with the standalone profiler in a "Windows Develop" build.

    5000 agents. Unity's automatic internal transform syncing takes ~4.5 ms:
    Unity_0B22HsLxZs.png

    15000 agents. Syncing takes ~18ms:
    Unity_RMGgYbspkI.png

    Obviously there's a lot of room there for my entities related stuff to be done off the main thread - but if I wanted to say animate these sprites using built in tools as well, it just wouldn't be viable at this scale.
     

    Attached Files:

  11. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,200
    I have a GameObject-based project that I have used for teaching people Unity and I would love to make a DOTS equivalent and expand on it (especially with Tiny). However, it makes heavy use of line renderers and lots of small 2D lights.
     
  12. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    For a one-word answer: size.
    Games like Dwarf Fortress, Prison Architect, and Rimworld are inspirations for my project. But they are somewhat limited. In complexity and/or in size, in areas, I'm interested in. I want a better simulated and bigger colony builder. So I've turned my eyes to DOTS.
    2d rendering was a wall I hit when prototyping. I of course can use an "old" 2d toolset but then I will need heavy optimization. Hybrid components seem to resolve the connection between the "old" and "new" way of doing things but still, it will need optimization. The good thing is I can have calculations on the DOTS side.
    As I've searched for an alternative I looked into project Tiny. As stated above, it won't work with standard DOTS, so it's a dead end. It seems com.unity.2d.entities has the same components as I would probably write so writing my own solution when Unity has a solution, and probably will adapt it in near future, but still there are no plans for it as I understand.
    The last option is to make my own 2d rendering systems, like one Sarkahn and the others made. But it seems to be overkill in the prototyping stage.

    As for the toolset, an OOP solution has everything I would gladly use: SpriteRenderer, Sprite tools, Sprite animations, IK, atlas baking, and tile maps. The new 2D Lights are also interesting, as I would need top-down (or semi top-down) lighting in my game.

    Sadly I didn't perform any performance test, as I've assumed the game to be big. I want to push it as far as I can.
     
    Aratow and NotaNaN like this.
  13. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    904
    Thank you for all your feedback and insights. The reason why I am asking for detailed information about the performance limitations you are experiencing, is because we have multiple avenues that we are actively working on and/or considering.

    For instance, you may or may not know that we have optimized the internals of both SpriteShapes and 2D Animation (SpriteSkin) using Burst, Collections and Jobs. The requirements from a user is very minimal to enjoy these performance boosts, and lets them continue using Unity as they have been previously without learning about ECS.

    Of course, these internal changes doesn't work for every problem, but the more we know about what you are trying to create, and the limitations you are facing, the more we can customize our solutions to help you.

    Keep the feedback coming, I'll keep an eye on this thread.
    Thanks!
     
    NotaNaN, SirStompsalot and Krajca like this.
  14. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    I just wanted to chime in here and say I would very much like to see 2D Support in DOTS and the ECS ecosystem. We use 2D exclusively and so far the tools have been spot on. 2D lighting is wicked and while there are some things that are a little clunky (i.e. we have to parent a gameobject to a particle effect to get 2d light particles as seen below) it works really well. We use tilemaps and multi-part sprites and while our projects aren't nearly as complex as say Tails of Iron we still chug along.

    2021-01-08.gif

    But one of the biggest bottlenecks is 2D Rendering. Sure, we can absolutely take a game object with a sprite renderer, convert it to an entity and work with it (using the hybrid renderer of course).. But what if lighting is really important to us? There's currently no 2D light support in ECS.

    The other big problem is sprite animation. There are great projects out there for animating sprites via spritesheets in ECS, but the developer mindshare for ECS at the moment waxes and wanes frequently. So we can either write our own animator in ECS, leave them in monobehaviors & classic animator systems. I did have a lot of success animating 50000 entities using flipbook shaders, but flipbooks really aren't appropriate for everything.

    2021-01-09.png

    None of the problems are insurmountable, but as soon as we start requiring to render more than 1000 sprites which move, collide and animate at the same time, ECS looks really appealing. The downside is that 2D is a second class citizen of sorts when compared to 3D and project tiny.
     
    NotaNaN likes this.
  15. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Sorry if I misunderstood something but if you attach a sprite renderer to your entity as a hybrid component then any existing 2d lighting solution should just work, since it's still just the normal sprite renderer. The "hybrid" part just means unity will automatically sync the position of the rendered sprite to match the translation of the entity it's attached to. As I showed above though that syncing process is not cheap
     
  16. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Sorry for the misunderstanding. I was referring entities support for 2d lights, i.e. converting lights to entities. . A use case might be a character walking around in the dark carrying a torch, but that use case doesn't work at the moment.
     
    Sarkahn likes this.