Hey everyone,
I’ve been doing my own research studying about ECS, Jobs, Burst and making videos covering what I’ve learned so that you can learn too. I’m loving the insane performance benefits the DOTS stack provides.
This video is a very nice showcase of what can be done with ECS, here you have a bunch of Marines shooting at thousands of Zombies. You can get the project files from the website.
Also I’ve only been researching ECS for a few weeks so it’s possible that some problems have better solutions than what I’ve come up with so if you notice something that doesn’t seem right or there’s a better way of doing please let me know!
Nice tutorials! Keep up good work!
Also I’ve been making a space invaders style game for kata purposes for some time. Hopefully next week I’ll be ready to capture a tutorial about what I’ve learned. I’ve got something funny in my mind to keep people in pace while I am talking about cpu caches and stuff
I’m interested in drawing sprites. I made a totally different way to go about it. I’m managing a single huge mesh. The sprites are then just indeces to four vertices in this single mesh. Before rendering, I transform the vertices of the mesh using the LocalToWorld of each sprite. This is relatively fast when burst is enabled. This way, I can guarantee a single draw call for at least 16,380 sprites using a single material. The only downside is that I have to copy a maintained native array of vertices, uvs, colors into managed arrays so they can be set into the Mesh.
Using a RenderMesh for a sprite atlas means that there would be multiple meshes since they have different UVs. I’m not sure of the effect of this in terms of instancing. Would this result to more draw calls? Would this be faster compared to my method?
I’ve been following your ECS videos over the past few weeks. Seriously good work.
I commented a while back on one of your videos saying how it would be good to see a tutorial on the new physics engine. Creating physics bodies from code, object hierarchy and how to manage them in ECS, etc.
The video going live later today covers a very simple Sprite Sheet Animation system, should be a great starting point for anyone looking into ECS Animation.
Using a single mesh for animating a bunch of units is something I’d like to research, currently working on testing Graphics.DrawMeshInstanced which also seems like an interesting approach.
Meshes with different UVs do indeed break GPU Instancing however you can still use Dynamic Batching so your approach should provide good results.
The Marines Vs Zombies video uses Dynamic Batching to manage the draw calls, each Unit has its own different mesh.
Yeah Physics is something I haven’t yet researched. Hopefully this week I’ll be able to finish my Animation research and get onto Physics.
Thanks for the comments everyone! Glad you like the videos!
Let’s implement the Simplest form of Animation in Unity ECS using Sprite Sheets.
The video covers making a Component to hold Animation data, a System to animate it and another System to render it using Graphics.DrawMesh();
In a future video I will cover using Graphics.DrawMeshInstanced(); to see just how far we can push this.
I like the Sprite animation vid. I’d really love it if Sprite animations worked for ECS, it’s cumbersome translating data back/forth between ECS and GameObjects. But there’s no easy alternative when using large HD Sprites, I need the tightly packed Atlases from huge textures, and the current Sprite / Animation classes don’t seem fit to efficiently translate into ECS.
Would indeed be great to have some functions to access the automatic sprite atlas that Unity generates. If we could get the generated texture and the coordinates of each Sprite that could help make the process easier.
I definitely want to look into Project Tiny in the future, trying to make a really small fully ECS based game sounds like a great challenge.
I’ve been working on getting the most performance out of Graphics.DrawMeshInstanced(); and I’ve managed to get it running with 200,000 individually animated sprites! That’s insane!
You can try SpriteUtility.GetSpriteTexture which can give you the atlas texture. Then you can get vertices, triangles and atlas uv coordinates from SpriteRenderer.sprite.
I briefly looked into this to see if I could generate a RenderMesh and material from the Sprite but got stuck cos SpriteUtility is in the Editor namespace and I couldn’t work out how to get the atlas texture at runtime. I didn’t push beyond that with my limited knowledge but I’m sure you’d be able to work it out.
Also looking into Tiny, I notice it has a Unity.Tiny.Core2D.Sprite2D (which is the Sprite component) with the following summary.
There’s also the Sprite2DSystem ComponentSystem in the same file and looks like a good place to start to replicate ecs sprite mechanics. I don’t know if the atlas (Image2D) Tiny uses is at all related to Unity’s sprite atlas though or whether it has its own custom version.
I’m on linux which doesn’t support tiny yet so can’t delve much deeper but you might find useful info there. It all looks pretty cool.
Let’s make a Quadrant System in Unity ECS to solve problems related to Unit Positions like a Targeting System or Obstacle Avoidance.
It’s a great system for placing Entities into separate buckets for easier searching. Awesome for any kind of algorithm that requires identifying nearby Entities like Find Target or Obstacle Avoidance or as used in the Boids demo.
Let’s spawn 100,000 Animated Sprites in Unity ECS!
We’re using Graphics.DrawMeshInstanced(); in order to draw all of our Units. Doing it this way we can massively benefit from the Job System to create various jobs to prepare the data before doing just a few Draw Calls.
The end result in this scene is 100,000 units but if the Sprite sheet is correctly set up to minimize overdraw we can push it past 200,000!
Looking Awesome, but how to deal with different sprites/materials,
also found if you want to move sprites need fix in “SpriteSheetAnimation_Animate” spriteSheetAnimationData.matrix update.
Switching and handling multiple Animations (Walk, Idle) is something I’m currently researching.
What fix do you need to move the sprites? It works fine for me if I just have a System moving the Translation.
Hey everyone!
I’m back to making Unity DOTS / ECS Video Tutorials.
Last I touched DOTS was 6 months ago so first thing I did was look at what changed.
Thankfully while things have improved significantly there haven’t been many breaking changes so almost everything in those older videos is still up to date.
Here are the latest videos: