❗❗ *Caution:* This video was made using an older version of Unity ECS. While the core concepts remain the same, some of the API and workflows have changed as of ECS version 1.0. I would recommend checking out my ECS 1.0 tutorial video for a good overview of the latest standards for Unity’s DOTS: th-cam.com/video/IO6_6Y_YUdE/w-d-xo.html Once again, the theory behind the concepts of this video are still relevant, however the API has changed. Stay tuned for further updated videos on this subject. Please let me know if you have any questions either here or in our Discord community: tmg.dev/Discord
Almost all of my prefabs are instantiated via ECB, but there is one system where some prefabs are instantiated via EntityManager... And I've always wondered why they flicker for the first frame. So now I know! Thanks for the awesome vid!
Awesome, glad this gave you some clarity on that! Looking forward to seeing how you've dealt with the problem I'll be going over in next week's video when using prefabs with ECBs (or if you've even ran into that issue)
TH-cam is really annoying with that sometimes and they end up deleting legitimate comments that they think are spam... I've added you as an approved commentor, so hopefully this shouldn't happen again
Not OP but, lots of programmers (me included) are far more comfortable doing everything in code. It's more automatable, better for SCM, and easier to understand exactly what's happening. My Unity scenes are typically just a camera with a bootstrap script on it.
Great question, yes you can! You can create what is called as a "Custom Authoring Component" that gives you a bunch of flexibility about which components get added to the converted entity and you can even initialize them with specific values as you see fit. You just need to have your MonoBehaviour implement the IConvertGameObjectToEntity interface and define what you want to happen in the Convert() method. I think I have an older video on custom authoring components, but there is a good example of them in the video I just put up today - the one on making a stealth state machine in Unity ECS.
Interestingly, I don't need the [updatebefore] attribute as the spawn occurs before transform system group in my case. Not sure if this is because I am using the latest unity version and latest ECS version. In any case, thanks for the video. Btw, you did not mention about how to set up the "spawner" in the hierarchy. It takes me some time to figure it out.
The system update order is arbitrary but deterministic. Basically it means that if you don't specify any update before/after attributes for a new system, it will just go at a more or less random spot in the Simulation System Group - sometimes it may naturally be before or after the transform system group. But once the order has been set by Unity, it will always update in that same spot until you override that set order by using one of the attributes. I do have a video on here talking more about system update order if you are curious - th-cam.com/video/oX0NElpfXgg/w-d-xo.html Hope that helps!
@@TurboMakesGames The video is great. As a newbie, I am still not sure about how "schedule parrallel", schedule, run etc fits in the system update order. It would be great to have a video talking about this.
@@jimmyyu3383 I have a video on system update order, but to answer your question more directly - the system update order determines when a system executes in relation to other systems in your project. By doing a .Run(), the code in the job executes immediately on the main thread. When you do a .Schedule() the work in that job is just scheduled, but doesn't execute until an available worker thread can run that work. Jobs get executed in the order they are scheduled, by using the UpdateAfter/Before attributes you can effectively control the order your jobs get played back in. ScheduleParallel() is the same as Schedule, but it can run on multiple worker threads rather than just one. Hope that helps!
I kinda wonder the real use case here. Let's say my location is tropical island so there are required many maybe thounds of different trees, not just few types like in usual forests. I tried many stuff VSP or GPUi, but does trees are actual ECS use case? Batching is great when it comes just for few models mass placed, but I'm getting real headaches with specific amount of trees that drastically impacts performance.
Most of the advantages of ECS are on the CPU and memory side. While the hybrid renderer does help with rendering performance, if you're running into some limits with the hybrid renderer with thousands of different types of trees then you might need to look elsewhere for that part specifically
So if I understand correctly updating the Translation/Rotation in SimulationSystemGroup can always cause incorrect rendering, not just when instantiating prefabs, because my system could run after the TransformSystemGroup, correct? Since you are not supposed to work with LocalToWorld, I wonder why the TransformSystemGroup does not make use of OrderLast = true and is not a child of LateSimulationSystemGroup. That way it would always run after normal systems by default and you wouldn't have to add [UpdateAfter(typeof(TransformSystemGroup))] to every single system that writes to Translation or Rotation. Do you have an idea why they didn't do it that way? Do you know why someone would not want TransformSystemGroup to run at the end of SimulationSystemGroup?
You're allowed to work with LTW, just not recommended when also using TRS components, due to the TransformSystemGroup. I've not had any problems with rendering prefabs, though I have gotten use to pre-defining prefabs with negative Y values to keep solely the instantiated frame out of camera view. Never had a problem after the first frame, though. It's probably just me, but I find it easier to have my own TRS systems in PresentationSystemGroup, as the half frame it takes to hit the LTW update is negligible, while allowing a lot of flexibility...
@@jakehix8132 My point is that if I understood correctly you have a 50% chance to have a 1 frame delay until your changes to TRS hit LTW if you are running in SimulationSystemGroup and didn't specify an UpdateBefore and this can cause incorrect rendering. Of course a one frame delay is negligible in most cases, but still I wonder why TransformSystemGroup doesn't use OrderLast=true to avoid this. Especially since most people will not modify LTW directly as it is overridden each frame anyways. Is there anything I missed?
@@Adrodoc Honestly, I just have my own pair of SystemGroups in SimulationSystemGroup that either runs before TransformSystemGroup or is not affected by it. This way I can easily group the systems that do translations on TRS components to the group that is guaranteed to run before TSG. It's just a handful of lines of code and makes everything quite obvious. Never had a problem since doing that. With ECS you just need to be a bit more aware of what's going on "under the hood" and what Unity's default systems are doing than in regular Unity, but it's not like you need to understand everything perfectly. Just understanding the data flow is enough and planning for it accordingly.
I'm having one problem that I don't see other having -- I can instantiate a prefab (it shows up clearly in the DOTS hierarchy, and I can instantiate as many as I'd like) but the game object doesn't appear in either the scene or game view. I'm using Unity 2021 LTS & ECS 0.51. Is there some obvious setting that perhaps I've missed?
@@TurboMakesGames I don't -- I'm creating a blank default 3D scene using 2021.3.10f1 and importing Entities 0.51.1-preview.21 - August 02, 2022. I've reproduced the effect using a blank URP 3D project. Both of these are on a Mac, but additionally I've exactly recreated the problem on my Windows machine. So quite likely there's some setting toggle I haven't switched since it's happening cross platform. I'm a bit out of ideas.
@@mattabrams3841 Unfortunately I didn't. I decided to abandon DOTS until it got a bit more stable (things look better now, but maybe not?). Let me know if you track down a solution.
@@nazarremerchant I noticed that my entities graphics was randomly no longer in my package registry. Super simple answer, just very unexpected behavior. I would double check the preview packages aren’t giving you any issues lol
Im currently working on a project that requires ECS to function, but It's on 2021! I can't use ECS until 0.51 comes out. What do you recommend I do in the mean time to prepare so that the time isn't wasted?
Kinda depends on you. If it's a large project, there's surely plenty of non-code related work to be done. There shouldn't be just one instance that ECS will make or break a project in, though. Things like the Burst compiler and Jobs systems are already dev ready. ECS itself isn't exactly an upgrade to just a segment of a project.
I've heard people having various results with using ECS on 2021. While it isn't officially supported, you may be able to get it working. No guarantees though so take some good backups before you try it!!
Quick feedback: you tend to waste a lot of time explaining or just talking about useless stuff and when it comes to actual important stuff you just don't explain at all. This comes from the perspective of someone who doesn't know how to use ECS at all. Like for instance, when spawning and setting a new position you create a new translate thingy instead of modifiying the existing one. That seems to me like useless garbage being produced. Why, tho? Would seem like it's worth mentioning. The actual code part was very mysterious to me. Overall the only thing I did learn from this video was the execution order tip and how to reference the prefab. What's the entitymanager or any other of those classes you reference and create new instances of? No idea. To me at least would be much appreciated if you'd consider people watching are complete noobs and quickly get over how things work instead of considering we already know stuff. No need to explain deeply, just an overview or maybe reference to other videos? Everytime I watch one of your videos I feel like I don't understand/know anything and need to learn so much before watching this, let alone effectively using ECS on a project of my own
Hey Tom, really appreciate your feedback from your perspective here - this will certainly help my videos going forward. ECS is tough because many of the concepts build off other ones so I can definitely understand how challenging it may be to jump in without certain background knowledge. In most cases if I brush over a topic like the Entity Manager, etc. I've done a dedicated video on it - though I could definitely do a better job at referencing those videos or even making an ECS basics video series to give a high-level overview on the important concepts. I do have some things planned in the near(ish) future that will go over the full process of creating an ECS project where I'll go into more specific detail on everything that is going on. To the point to brought up regarding why I created a new translation component rather than modifying the new one - I actually don't think I've discussed specifically why that is. Reason is that in ECS, data components are all value types, so if we were to get the existing data component, we'd only be working with a copy of that data - so after our modification we'd still have to set the translation component on the entity. By creating a new translation component, it saves us the step of getting the existing translation component, which isn't necessary in this case. Either way we are allocating memory for the new translation component, so again it just saves us the one line of code where we get the existing one. Hope that makes sense. On a side note - in Entities.ForEach functions, we can modify the data components directly because we pass them into the function by reference using the ref keyword. ECS can definitely be confusing and overwhelming at first, but I believe that if you continue to expose yourself to the concepts like you are, you'll start to pick more of it up and piece things together. Truly, thanks again for the feedback and wishing you all the best with learning ECS. Let me know if there is anything else you might have questions on or that I could better clarify. Have a great one!
@@TurboMakesGames nice, perfectly explained, now I understand! Reference and value types is something you can assume your audience knows. If u had brefly mentioned it, I'd have gotten it. Maybe something that would seem obvious to many but the normal Unity workflow doesn't often make us think if a field is acessed by reference or not, right? That kind of "flip" in the way things go on ECS are always good to reinforce. I also feel those small things enrich the content, deepens our learning as viewers. No need to go far, overthink or overexplain. Some knowledge is best learnt when mindsets (hate this word.. ways of thinking?) or concepts are reinforced many times superficially rather than a long complex dive into it, right? From an educator's perspective Anyhow, glad the feedback was productive for you and thanks for explaining!
❗❗ *Caution:* This video was made using an older version of Unity ECS. While the core concepts remain the same, some of the API and workflows have changed as of ECS version 1.0. I would recommend checking out my ECS 1.0 tutorial video for a good overview of the latest standards for Unity’s DOTS: th-cam.com/video/IO6_6Y_YUdE/w-d-xo.html
Once again, the theory behind the concepts of this video are still relevant, however the API has changed. Stay tuned for further updated videos on this subject. Please let me know if you have any questions either here or in our Discord community: tmg.dev/Discord
Almost all of my prefabs are instantiated via ECB, but there is one system where some prefabs are instantiated via EntityManager... And I've always wondered why they flicker for the first frame. So now I know! Thanks for the awesome vid!
Awesome, glad this gave you some clarity on that! Looking forward to seeing how you've dealt with the problem I'll be going over in next week's video when using prefabs with ECBs (or if you've even ran into that issue)
Thank you sooooo much! Thank you Turbo! Great work, Great Tutorial!
Hello, so glad to hear you found this helpful, cheers!!
Why I can't keep post! It's always been delelte automatically.
TH-cam is really annoying with that sometimes and they end up deleting legitimate comments that they think are spam... I've added you as an approved commentor, so hopefully this shouldn't happen again
@@TurboMakesGames Thank you, I send this post for 4 times, finaly I write very simple it's been keeped. lol
this is great buf a while ago i have decided to make everything on my project with code even load assets with code
Any particular reason you went that way, and decide to keep doing it that way?
Not OP but, lots of programmers (me included) are far more comfortable doing everything in code. It's more automatable, better for SCM, and easier to understand exactly what's happening. My Unity scenes are typically just a camera with a bootstrap script on it.
if i create monobehaviours - can i define which component they get turned into?
Great question, yes you can! You can create what is called as a "Custom Authoring Component" that gives you a bunch of flexibility about which components get added to the converted entity and you can even initialize them with specific values as you see fit. You just need to have your MonoBehaviour implement the IConvertGameObjectToEntity interface and define what you want to happen in the Convert() method. I think I have an older video on custom authoring components, but there is a good example of them in the video I just put up today - the one on making a stealth state machine in Unity ECS.
Hi Turbo, I miss file "SpawnedCapsuleBufferElement.cs" in your download prj. And where I can get this file? Thanks
Thanks for letting me know, I've updated the project files on the download link and they should include the file I missed, cheers!
Interestingly, I don't need the [updatebefore] attribute as the spawn occurs before transform system group in my case. Not sure if this is because I am using the latest unity version and latest ECS version.
In any case, thanks for the video. Btw, you did not mention about how to set up the "spawner" in the hierarchy. It takes me some time to figure it out.
The system update order is arbitrary but deterministic. Basically it means that if you don't specify any update before/after attributes for a new system, it will just go at a more or less random spot in the Simulation System Group - sometimes it may naturally be before or after the transform system group. But once the order has been set by Unity, it will always update in that same spot until you override that set order by using one of the attributes. I do have a video on here talking more about system update order if you are curious - th-cam.com/video/oX0NElpfXgg/w-d-xo.html
Hope that helps!
@@TurboMakesGames The video is great. As a newbie, I am still not sure about how "schedule parrallel", schedule, run etc fits in the system update order. It would be great to have a video talking about this.
@@jimmyyu3383 I have a video on system update order, but to answer your question more directly - the system update order determines when a system executes in relation to other systems in your project. By doing a .Run(), the code in the job executes immediately on the main thread. When you do a .Schedule() the work in that job is just scheduled, but doesn't execute until an available worker thread can run that work. Jobs get executed in the order they are scheduled, by using the UpdateAfter/Before attributes you can effectively control the order your jobs get played back in. ScheduleParallel() is the same as Schedule, but it can run on multiple worker threads rather than just one. Hope that helps!
Are you planning to convert the old video to version ECS 0.51?
Which old video? This one was made on 0.50, which is fundamentally the same as 0.51
I kinda wonder the real use case here.
Let's say my location is tropical island so there are required many maybe thounds of different trees, not just few types like in usual forests. I tried many stuff VSP or GPUi, but does trees are actual ECS use case? Batching is great when it comes just for few models mass placed, but I'm getting real headaches with specific amount of trees that drastically impacts performance.
Most of the advantages of ECS are on the CPU and memory side. While the hybrid renderer does help with rendering performance, if you're running into some limits with the hybrid renderer with thousands of different types of trees then you might need to look elsewhere for that part specifically
So if I understand correctly updating the Translation/Rotation in SimulationSystemGroup can always cause incorrect rendering, not just when instantiating prefabs, because my system could run after the TransformSystemGroup, correct?
Since you are not supposed to work with LocalToWorld, I wonder why the TransformSystemGroup does not make use of OrderLast = true and is not a child of LateSimulationSystemGroup. That way it would always run after normal systems by default and you wouldn't have to add [UpdateAfter(typeof(TransformSystemGroup))] to every single system that writes to Translation or Rotation.
Do you have an idea why they didn't do it that way? Do you know why someone would not want TransformSystemGroup to run at the end of SimulationSystemGroup?
You're allowed to work with LTW, just not recommended when also using TRS components, due to the TransformSystemGroup.
I've not had any problems with rendering prefabs, though I have gotten use to pre-defining prefabs with negative Y values to keep solely the instantiated frame out of camera view. Never had a problem after the first frame, though.
It's probably just me, but I find it easier to have my own TRS systems in PresentationSystemGroup, as the half frame it takes to hit the LTW update is negligible, while allowing a lot of flexibility...
@@jakehix8132 My point is that if I understood correctly you have a 50% chance to have a 1 frame delay until your changes to TRS hit LTW if you are running in SimulationSystemGroup and didn't specify an UpdateBefore and this can cause incorrect rendering. Of course a one frame delay is negligible in most cases, but still I wonder why TransformSystemGroup doesn't use OrderLast=true to avoid this. Especially since most people will not modify LTW directly as it is overridden each frame anyways. Is there anything I missed?
Could not tell you why they did not set it up as you described - things like this could definitely change in future versions though.
@@Adrodoc Honestly, I just have my own pair of SystemGroups in SimulationSystemGroup that either runs before TransformSystemGroup or is not affected by it. This way I can easily group the systems that do translations on TRS components to the group that is guaranteed to run before TSG. It's just a handful of lines of code and makes everything quite obvious. Never had a problem since doing that. With ECS you just need to be a bit more aware of what's going on "under the hood" and what Unity's default systems are doing than in regular Unity, but it's not like you need to understand everything perfectly. Just understanding the data flow is enough and planning for it accordingly.
I'm having one problem that I don't see other having -- I can instantiate a prefab (it shows up clearly in the DOTS hierarchy, and I can instantiate as many as I'd like) but the game object doesn't appear in either the scene or game view. I'm using Unity 2021 LTS & ECS 0.51. Is there some obvious setting that perhaps I've missed?
Do you have the DOTS netcode packages installed as well? If so, there may be some extra steps you need to do to display them in your "client world"
@@TurboMakesGames I don't -- I'm creating a blank default 3D scene using 2021.3.10f1 and importing Entities 0.51.1-preview.21 - August 02, 2022. I've reproduced the effect using a blank URP 3D project. Both of these are on a Mac, but additionally I've exactly recreated the problem on my Windows machine. So quite likely there's some setting toggle I haven't switched since it's happening cross platform. I'm a bit out of ideas.
Did you ever happen to solve this? I know the package has changed a lot, but I'm experiencing something similar (2D)
@@mattabrams3841 Unfortunately I didn't. I decided to abandon DOTS until it got a bit more stable (things look better now, but maybe not?). Let me know if you track down a solution.
@@nazarremerchant I noticed that my entities graphics was randomly no longer in my package registry. Super simple answer, just very unexpected behavior. I would double check the preview packages aren’t giving you any issues lol
Im currently working on a project that requires ECS to function, but It's on 2021! I can't use ECS until 0.51 comes out. What do you recommend I do in the mean time to prepare so that the time isn't wasted?
I'd say downgrade to 2022 if possible. If you're gonna wait until the next update, you're probably going to be waiting a while.
@@user-gl1ls1jx3h downgrade to 2020 you mean?
Kinda depends on you. If it's a large project, there's surely plenty of non-code related work to be done.
There shouldn't be just one instance that ECS will make or break a project in, though. Things like the Burst compiler and Jobs systems are already dev ready. ECS itself isn't exactly an upgrade to just a segment of a project.
I've heard people having various results with using ECS on 2021. While it isn't officially supported, you may be able to get it working. No guarantees though so take some good backups before you try it!!
Test
Received.
Quick feedback: you tend to waste a lot of time explaining or just talking about useless stuff and when it comes to actual important stuff you just don't explain at all. This comes from the perspective of someone who doesn't know how to use ECS at all. Like for instance, when spawning and setting a new position you create a new translate thingy instead of modifiying the existing one. That seems to me like useless garbage being produced. Why, tho? Would seem like it's worth mentioning.
The actual code part was very mysterious to me. Overall the only thing I did learn from this video was the execution order tip and how to reference the prefab.
What's the entitymanager or any other of those classes you reference and create new instances of? No idea.
To me at least would be much appreciated if you'd consider people watching are complete noobs and quickly get over how things work instead of considering we already know stuff. No need to explain deeply, just an overview or maybe reference to other videos? Everytime I watch one of your videos I feel like I don't understand/know anything and need to learn so much before watching this, let alone effectively using ECS on a project of my own
Hey Tom, really appreciate your feedback from your perspective here - this will certainly help my videos going forward. ECS is tough because many of the concepts build off other ones so I can definitely understand how challenging it may be to jump in without certain background knowledge. In most cases if I brush over a topic like the Entity Manager, etc. I've done a dedicated video on it - though I could definitely do a better job at referencing those videos or even making an ECS basics video series to give a high-level overview on the important concepts. I do have some things planned in the near(ish) future that will go over the full process of creating an ECS project where I'll go into more specific detail on everything that is going on.
To the point to brought up regarding why I created a new translation component rather than modifying the new one - I actually don't think I've discussed specifically why that is. Reason is that in ECS, data components are all value types, so if we were to get the existing data component, we'd only be working with a copy of that data - so after our modification we'd still have to set the translation component on the entity. By creating a new translation component, it saves us the step of getting the existing translation component, which isn't necessary in this case. Either way we are allocating memory for the new translation component, so again it just saves us the one line of code where we get the existing one. Hope that makes sense.
On a side note - in Entities.ForEach functions, we can modify the data components directly because we pass them into the function by reference using the ref keyword.
ECS can definitely be confusing and overwhelming at first, but I believe that if you continue to expose yourself to the concepts like you are, you'll start to pick more of it up and piece things together. Truly, thanks again for the feedback and wishing you all the best with learning ECS. Let me know if there is anything else you might have questions on or that I could better clarify. Have a great one!
@@TurboMakesGames nice, perfectly explained, now I understand! Reference and value types is something you can assume your audience knows. If u had brefly mentioned it, I'd have gotten it. Maybe something that would seem obvious to many but the normal Unity workflow doesn't often make us think if a field is acessed by reference or not, right? That kind of "flip" in the way things go on ECS are always good to reinforce.
I also feel those small things enrich the content, deepens our learning as viewers. No need to go far, overthink or overexplain. Some knowledge is best learnt when mindsets (hate this word.. ways of thinking?) or concepts are reinforced many times superficially rather than a long complex dive into it, right? From an educator's perspective
Anyhow, glad the feedback was productive for you and thanks for explaining!