UPDATE April 2023: Since I posted this original video, there have been a number of breaking changes in the latest version of the ECS API. While the main concepts are all still the same, the implementation details are slightly different. As such, I've created an article detailing these changes that you can reference as you go along: www.tmg.dev/tuts/zombieupdate/
I finally decided today was the day I was going to learn ECS, but it's disappointing to see all the things that have changed since this video was made a year ago. I get a video like this is an undertaking, but before I get started trying to sort-out the changes, I just want to make sure...you're not planning an update if I wait a week or two, are you?
Thank you for this tutorial! Although I have been using Unity for a while now ECS is still pretty daunting to me. I find that DOTS get very technical very quickly so videos like these are a huge help for quickly getting me to a point where I can start to experiment with game mechanics (instead of me struggling to figure out how to structure my code, what classes to use, etc). I'm hoping you'll turn this into a series in which you build popular game mechanics, but with DOTS/ECS (like you've done on smaller scale in the past but for 1.0). I think that's something that'll really help more people hop on the DOTS/ECS train. Since the Unity team doesn't seem to care to do this themselves it is up to the community and you're doing a fantastic job.
Thank you so much for the support Arveus!! Really great to hear these kinds of videos are helpful to you to get you up and running with a working knowledge of these concepts. Really appreciate the feedback too - those are definitely some things I'd like to do and have some cool ideas for videos along those lines. All the best!
If you aren't seeing entities in the Scene View but you can still see them in the Game View - open the Preferences window (Edit > Preferences...) then on the Entities section, make sure "Scene View Mode" is set to "Runtime Data" not "Authoring Data"
I have vica versa :)) I was following CodeMonkey's tut, my entities position is updating, but capsula stays still. Entity has capsula as a child. Also I can see capsula in Scene view and in Main Camera small window (when i select Camera in hierarchy), but i don't see it in Game window :( where cound be the issue?
I was just looking around for 10minutes and thought "Hey maybe someone commented something" Thank you for being that guy, saved me some trouble. Cheers!🍻
i took now 4 days fulltime and worked trough your tutorial and now got my own "game" to expand on it, thank you so much, wouldnt had been able to learn and progress so far with just unitys documentation or get here at all
Duuude, thanks for being one of the only quality up to date DOTS resources. Its rough to have to navigate through so many legacy systems and depreciated concepts when trying to do simple tasks.
Unity really should hire you to promote DOTS, because you're doing fantastic job! I feel like Unity is finally on a way to create something beautiful and really powerful with DOTS, because I, personally, see huge potential in it
Following along with the tutorial.... At 39:11 when I set the inspector to "run-time" with the yellow circle, it just says "Invalid Entity The entity does not exist anymore, please unlock inspector if it is locked or re-select." The inspector info for the brains object shows but not for the tombstone. I guess it's not baking for some reason? Anyone else getting this problem? The Inspector is unlocked and I have re-selected even re-created the object and the pre-fab that gets attached to it trying to troubleshoot.
Really love your ECS videos Johnny. Clear, concise, practical examples, and a little nerd humour .... love it man. Keep up the great work brother. We appreciate you man.
Amazing job on this, Johnny! I just finished the Spawning Zombies section and a minor change that I had to make was scheduling the SpawnZombieJob rather than running it on the main thread. Without doing that, it was producing an error associated with a scheduling dependency conflict with TransformToMatrixSystem:TransformToMatrixJob to access LocalToWorldTransform. I'm using the just-released Unity 2022.2.0b13 and the EntitiesGraphics 1.0.0-exp.14.
Yeah that must have just been a roll of the dice about how your systems got ordered vs. how mine were. Yes, scheduling the job would appropriately account for any dependencies so that is an adequate solution 👍
I appreciate you mentioning that ECS is not very beginner friendly for people new to C# and Unity. I thought I was just dumb for not understanding any of the ECS information I was trying to absorb in other tutorials, but now I realize that they're made for someone with more experience.
My man. I found your channel from Code Monkeys and what a joy this is. You are fantastic the way you talk, explain things, the details, quite direct on the case and no gibberish in between. You and Code Monkeys are my go to for Unity hands down! Keep up the good work, I am subscribing ;)
Not sure if I'm making a mistake or if something broke with the new LTS or ECS versions, but at 29:37 you add a gameobject to the sub scene and hit play and it displays as an entity. When I do that, the inspector just says it's an Invalid Entity.
Ok. This earned my subscription. I don't know anyone else doing stuff like this. I'm hoping ECS really comes into its own, ready and raring to go for when I start the project I think could really use it.
Covering the breaking changes including the recent revision article has been incredibly helpful. Tracking changes for Unity DOTS over the past few years has been a nightmare to get a firm grip on
If you still get InvalidOperationExceptions after adding the [UpdateAfter(typeof(SpawnZombieSystem))] in 1:36:36, I also had to add [UpdateBefore(typeof(TransformSystemGroup))] to the ZombieRiseSystem to resolve this issue.
This. Thank you very much. I did " state.CompleteDependency();" on SpawnZombieSystem.OnUpdate and it also "fixed" it but im assuming that without your approach, Rise job may run through another update tick, at least its the reasoning i can find about this error... Weird that Turbo didn't have this issue nor specified in the update thread...
Thank you! I can't start following along immediately because I'm about two thirds of the way through the 0.51 tutorial (which is brilliant by the way!), but very keen to work through it after.
Cool - hope the 0.51 video gave you some good exposure to the concepts and that it'll give you an appreciation for all the awesome new features in 1.0 😊
If your entities are not visible in Scene View but visible in Game View, open the Preferences window (Edit > Preferences…) then on the Entities section, make sure “Scene View Mode” is set to “Runtime Data” not "Authoring Data".
I am very grateful to you for this amazing video. I really learned a lot of things from it. I fully share your admiration for Unity DOTS and look forward to a full commercial launch. Thank you for all the hard work you put into this video
After finishing and implementing the whole video, this was really hardcore tutorial and full of information, but also very clean to follow along. Great job! Looking forward to more things like how to use NavMesh, physics, new Input system and animations with dots.
For only moving after rising around 1:51:58 I think it would be better to use without the RiseSpeed component since you remove that after rising. This saves you from having to remove and add components. Still great video though, thank you.
Hi! I'm new to ECS and following your tutorial which helps a lot. Following your video, I've got one question. (1:00:27) You set system's state to OnUpdate to wait until GraveyardProperties Singleton exists so that no reference error occurs. My question is, if you have to implement some method using OnUpdate function in same class, what will you do? Will you be able to easily implement it, or there is no way to guarantee singleton returned before OnCreate is called so you have to seperate GenerateSystem/LogicSystem unreluctantly, not to fulfill the responsibility of class? I mean, is there proper way to 'await' return of singleton class(and delay call of update) so that you do not need to implement generating process in update method. I'm wandering if ECS system having Awake/Start seperated would made this easier since we could simply secure singleton instance in awake and call it later in start or update in traditional unity system. Looking forward to your answer! Thanks in advance! (sorry for my short English, please be gentle if my sentences looked silly or rude)
Thanks for the tutorial! I really love it. Subscribed and bell on! I'm using Dots 1.0.0-pre.15 with Unity version 2022.2.0f1 I gather some issues that I found and share for who have problems like me. Notify me if any was wrong. :) 1. Change all UniformScaleTransform to LocalTransform, then -> ecb.SetComponent(newTombstone, newTombstoneTransform); You do not need to instantiate LocalToWorldTransform or LocalTransform. Just pass the variable in ecb.SetComponent(). 2. Error: "Loading Entity Scene failed because the entity header file couldn't be resolved. This might be caused by a failed import of the entity scene. Please take a look at the SubScene MonoBehaviour that references this scene or at the asset import worker log in A:\xxxxxx\ZombieBrainHunter-DOTS\Logs. scenePath=Assets/Scenes/GraveyardScene/GraveyardEntityScene.unity" Fix no.1: Add [ChunkSerializable] property for ZombieSpawnPoints script. (I got a message that unity told me to do for avoid this error) Fix no.2: Duplicate your objects in sub-scene and delete the old objects. 3. You might need to change trasformAspect.Position (Obsolete) to transformAspect.WorldPosition instead. Rotation as well But on ZombieRiseAspect, you might use .LocalPosition instead. I don't know why .WorldPosition make my zombies rise up from center of the world position. 4. Use [EntityIndexInQuery] instead of [EntityInQueryIndex] 5. If you try to get brain scale or get transform component Fix: Change GetComponent to GetComponent() after called you can just .Scale 6. Error:"InvalidOperationException: System.InvalidOperationException: GetSingleton() requires that exactly one entity exists that matches this query, but there are {0}. This Exception was thrown from a function compiled with Burst, which has limited exception support." Fix: Add state.RequireForUpdate(); in OnCreated() but if you on SystemBase you can cut "state." out and then RequireForUpdate();
1:34:25, It's confusing You created ZombieRiseJob struct, but didn't pass any ZombieRiseAspects (as it needs in Execute function) I thought there should be some SystemAPI queries to get all necessary data like aspects and components and pass through some worker thread (for example using Ijobs in your video) How does IjobEntity struct know there should be a ZombieRiseAspect? Is it the way how Aspects work in DOTS? Is it so that aspects need no queries in order to get them?
I'm done watching the whole video and it's interesting to know that you were recording for ~6 hours and then the final product is 2 hours and 27 minutes 😯, nice... and it seems that you know what you are talking about.. plus your code seems like well made so i'm really enjoying it especially to know more about ECS in Unity or in other words the Data-Oriented design... i'm a beginner so i'm just passing by right now in video about game developing then after watching them i am gonna go to pure C# programming...
Amazing tutorial. Thank you very much! So many topics covered, and we get a complete working project in the end It would have taken me months to learn and get everything covered in this video working myself by just using the official docs.
At 1:21:46 is there any particular reason to use a job, instead of directly decreasing the timer and spawning zombies in the OnUpdate function? Especially since we use Run(), which means that it's executed immediately in the main thread, I don't understand why it must be a job. Maybe my understanding is flawed? Appreciate if someone clarifies it for me
Thanks for the video a lot, one issue I have while following along is, I cannot see the IAspect which I created in the Aspects inspector in the play mode.
@@Heisenberg-xc8ub just to give info, even though it didn't show up in the aspecs section, my code works, system is able to retrieve the correct entities with that aspect.
How interesting - maybe just make sure you are in the "full entity mode" in the inspector rather than the hybrid mode? That would be the little orange circle is full rather than empty or partially full in the upper right. Glad to hear that it still works fine though!
@@hakanviajando Same issue for me in 2022.2.b13, anyway, since you say it works in code later at least I won't need to bash my head anymore trying to figure out if I did something wrong. Thanks.
Thank you for the effort, really useful video! I can't say I like the extra layers of complexity that entities 1.0 brings, but I guess that's because I prefer a code-only solution, and most of these seems to be implemented to get a better integration in the editor.
Glad you enjoyed the video. Fair enough - though thinking about it from Unity's perspective they need to have strong editor integration as production ready games will often have non-programmers working in the editor
Really great video as usual. Was the perfect video to get back into ECS after a longer break. I am running into some issue actually, which might be a very basic problem. Whenever I hit play, I can only see tombstones and Zombies in the game view but not the scene view. This is for both beta11 and beta13. Not sure if anyone has encountered this issue, but I'd appreciate if people who have encountered it before might be able to help. This is only for Entities spawned and does not affect other Gameobjects in the subscene.
@@JonasSchett Thank you. I was closing the Subscene in order to see them in editor. Also its no renamed to Scene View Mode = Runtime | Authoring Data. No transform handle, but guess we dont need that omg
Man thank you! I am already in the game industry, working in a game company and trying to improve my skills by learning the ECS. There is no other tutorial better than yours. :) I have a question: We have the zombie rise aspect and the local transform reference in it. So to my understanding; each entity has its own aspect because we can move them seperately or is there one for all zombie entities or is there one for all entities? I am not sure that I have understand the aspect concept fully.
To what I understood, aspects creation and assignation is all done under the hood. Every entites, that have all the components referenced on an aspect, have that aspect on them. You can look at the aspects of an entity in the Aspects Tab in the inspector in runtime mode. I may be wrong but it's what I understood after using them a bit 😁
Are you going to do a video on the new animation package? Would love to understand actual skeletal animation in dots. Also how does the rigging package fit in? And how does the playable API actually work? Every video I've found that is just about timeline, but it does so much more than that but I can't figure it out.
What animation package are you referring to? As of now, Unity doesn't have an officially supported animation solution for DOTS. However there are some other options available to you - forum.unity.com/threads/dots-animation-options-wiki.1339196/
The ZombieRiseSystem where you removed components (1:42:58) ran 5x slower than before (1:39:12). Why's that? Could it be because removing components is slow?
Removing components does take time, but it doesn't happen often so that's probably not why. I'd say it's more likely because of the other changes with the job like the parallel stuff.
Good observation - that is really interesting. My hunch would be that this increase is from getting the ECB singleton and creating the command buffer as this job just schedules the removal commands, not execute them. But I'd have to do some more testing to be certain.
Is there a specific reason why we create a NativeList just to use the ToArray() method on it in SpawnTombstoneSystem? Wouldn't it be better to directly create a NativeArray and avoid the ToArray() call?
Thanks for this turtorial! I really learned a lot of things from it. Besides, I'm confused about how to play animations and how to prevent objects overlapping. Would you plan to add these systems?
Glad it was helpful! ECS doesn't have a native animation solution yet, so you can either sync the entity with a GameObject for the visuals or use a 3rd party solution. The Unity forums has a DOTS animation section where someone has a post listing all the options. Preventing overlapping gets a bit more involved as you'll have to implement DOTS physics or build a custom avoidance solution. But this is something I'd like to cover at some point
Are there any changes in the way to change the materials settings of a single Entity (made from a prefab via a baker)? Or can I check your video about Material Overrides?
Material property overrides would probably be your best bet. Without getting into too much detail there are some efficiencies through using material property overrides without switching materials for an entity.
Hey Turbo. Been watching some/most of your ECS videos as they are definitely the top and go to resource for learning Unity DOTS in my opinion, but excuse me if I've missed one where you explain my following question. I've been trying to get a grasp on how 2D rendering works with Unity ECS outside of project tiny which seems abandoned at this point. I've seen some repos with custom Game Object to Entity Sprite Rendering conversions and I see that Unity ECS also now supports that conversion in subscenes. However from the limited understanding I still have of DOTS, I understand that sprites are still stored as reference types and thus can't be bursted. My question is, do you know what way or ways even, for working efficiently with 2D in Unity. My test case I want to make is a simple 2D platformer with # amount of entities, but I feel a bit blocked/gated by the lack of focus on 2D in Unity ECS. Can an image, say 16x16 pixel tile be stored as data/struct in e.g bytes with read/write access and have a system render said tile? I would greatly appreciate if you could give your insights on this or perhaps send me in the right direction. (Bonus subjects: 2D animation, 2D lights and tilemap in ECS). I love your videos, thanks for making such great content!
Hey there, thanks for the kind words and glad to hear these videos have been helpful to you!! Yes, so Project Tiny (now referred to as DOTS runtime) is on a development hold until after production-ready 1.0 is out. Right now, probably your best bet for 2D would be to render textures to a quad mesh. Though I will likely be chatting with some DOTS people at Unite next week so I'll see if I can get any insight from them on recommendations
I was thinking about the ZombieEatSystem. Do you know how the concurrency of EntityCommandBuffer.ParallelWriter is implemented? I would guess it is implemented with locks (but maybe that sortKey does some magic?). If that is true, then we could skip the ApplyBrainDamageSystem and just put a lock around the health of the brain directly instead. Another alternative would be to just not run the eating in parallel at all, as I suspect lock contention would take up the majority of the time of the eat code anyway. But maybe later we want to add more juice there, and it might be worth parallelizing again. Does Unity ECS ever do task level parallelism? as in, can it run two systems in parallel? If so, we could run the eat system sequentially but at the same time as some other system, that makes use of the rest of the cores/threads. Lastly, we could instead tally up the damage per thread, and then sum all damage that each thread accumulated. Whether this would be good or not depends on how many threads Unity spawns for these jobs. Do you know how it works here? Does Unity try to match threads with number of cores (or something like that), or does it have lots of threads decoupled from core count? Thanks in advance. :)
Thanks for the thoughtful comment. Unity takes care of a lot of the messy details though job dependencies and other safety checks. Though if you know what you are doing and you know you are writing to different places in memory from multiple threads, Unity does give you some tools to bypass their safety checks and other parallel restrictions - though showcasing those things would be far outside the scope of this video. "Systems" themselves can't run in parallel as they all run on the main thread - though systems often schedule jobs that run on worker threads and these jobs can all run in parallel, should they not have any overlapping dependencies. By default, Unity will assign one thread as the main thread and al the remaining threads on the CPU will be designated as worker threads. Any available worker thread can pull jobs from the queue for processing. Hope that helps!
Thanks for the video! I wonder if its worth going to DOTS if youre already building on top of Job System/Burst, from the optimization and possibilities perspective
Probably not. Unity was a leader in high fidelity cell phone games long before DOTS, so if you are already optimizing to the point of using jobs/burst, you're probably so cognizant of optimization that you likely have bigger bottlenecks elsewhere. Of course it all depends on your project. If you are dealing with 10,000s of dynamic objects, it could def help.
Technically speaking jobs/burst standalone are still considered "DOTS." If you are referring to ECS, then there are certain applications where switching to ECS would benefit. You can make a lot of things when starting with ECS, but switching to it is generally only a good idea for very specific use cases.
Great video, although I am stuck at the UniformScaleTransform. Rider doesn't find the type and I've been looking but can't locate it either. Where is it defined? I am using Unity.Entities and Unity.Transforms in the GraveyardAspect.cs. Or has the name changed in 2022.2.0f1?
1:25:27 -- getting this fun error: InvalidOperationException: The ComponentTypeHandle SpawnZombieJob.JobData.__DotsTutorial_Zombies_GraveyardAspectTypeHandle.GraveyardAspect__zombieSpawnPointsCAc can not be accessed. Nested native containers are illegal in jobs. The error goes away if I remove the "new SpawnZombieJob{}.Run()" block from OnUpdate. The error remains if I instead comment out everything in the Execute(GraveyardAspect aspect) function in SpawnZombieJob. The error also goes away when i remove any reference to the ZombieSpawnPoints object inside of GraveyardAspect. Is there some issue to be wary of when using a NativeArray inside a job? Unity 2022.2.5f1. Entities 1.0.0-pre.44.
update : I removed the job and put everything in OnUpdate [BurstCompile] public void OnUpdate(ref SystemState state) { var deltaTime = SystemAPI.Time.DeltaTime; var ecbSingleton = SystemAPI.GetSingleton(); var graveyardEntity = SystemAPI.GetSingletonEntity(); var graveyard = SystemAPI.GetAspectRW(graveyardEntity); var ECB = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged); graveyard.ZombieSpawnTimer -= deltaTime; if (!graveyard.TimeToSpawnZombie) return; graveyard.ZombieSpawnTimer = graveyard.ZombieSpawnRate; var newZombie = ECB.Instantiate(graveyard.ZombiePrefab); }
@@stonbax yeah my thinking, too. Or use UnsafeList for all of these operations (the only alternative I've seen so far, but idk how to implement it well and whether it it is a good idea in the first place)
gave up on creating GraveyardAspect. In unity 2023 several functions are already obsolete, and IAspect requires different implementation than in the video
Thank you for the tut! One question, what's the best way to handle passing back data to mono space? Say you wanted to keep track of the Brain Health in a UI?
I am marking a spot, survived 1h52minutes. That's too much for me. So much code for such a simple mechanic that I don't think I am going to implement it into my project, at least not yet. Looking at your new GDC video - I am hoping for the Rider integration at least. Video was great. Much respect. As the other dude says, in the second half you got so fast that I couldn't keep up and had to rewind the video all the time. No worries though, probably the best guide on RUclips for starters. Let's hope it does get simpler in future.
Nice almost 2hrs in, that's good! Definitely a lot all at once if you aren't familiar. Thanks for the feedback though, will certainly keep it in mind for future tutorials like this one
I was so hopeful watching this video, but sadly it seems as if the vast majority of it is out of date. Your update page doesn't even address all the inconsistencies that now exist. For instance, ISystem doesn't appear to have any members to implement. Is there an updated video you recommend?
Hey sorry to hear you've been running into some issues like that - for ISystem, there are now default implementations of the OnCreate, OnUpdate, and OnDestroy methods so you don't need to define the lifecycle methods you don't need, so you'll have to manually type them (or use an IDE template/macro to automate some of this for you). I don't know of a recent full project video, but I would highly recommend checking out the Unity ECS sample projects, they are a fantastic learning resource. github.com/Unity-Technologies/EntityComponentSystemSamples I will be doing a full project video with Netcode for Entities soon which will show all the latest API, however I'd recommend having some familiarity with ECS before that. In the meantime, let me know if there are any other issues you are running into! Or ask our Discord community - tmg.dev/Discord All the best!
Hey man, amazing job you did there! I was going to ask, how hard is possible to implement animation for like idle, attack, running type of things in ECS?
Unfortunately, there isn't an ECS compatible animation solution from Unity but it is still part of the "Planned" section of the DOTS roadmap. Check out this forum post by a community member talking about some of the options for animations in DOTS available now - forum.unity.com/threads/dots-animation-options-wiki.1339196/
Glad you enjoyed!! - Good question (I do plan on making an in-depth video on these later) but the main idea is so that multiple data components can be accessed through one single Aspect. In the past we needed to declare all the data components we needed and access each of them individually, which ended up leading to really messy systems. Putting the helper functions inside aspects further helps remove code from systems and put it in a place that makes more sense.
@@TurboMakesGames But now I have a problem. Now I can generate tombstones randomly, and tombstones of random size. Why can't I see tombstones in my Scene window? It can only be seen from the Game window. We look forward to your reply. Thank you!
@@Orange_-pp9nh You may just need to change your view settings for the scene view - open the Preferences window (Edit > Preferences...) then on the Entities section, make sure "Scene View Mode" is set to "Runtime Data" not "Authoring Data" Hope that helps!
@@TurboMakesGames Hello, I followed your tutorial to the time of 1:25:19, and then I ran. The zombie did not appear, but a bug appeared. The prompt message is:InvalidOperationException: The previously scheduled job TransformToMatrixSystem:TransformToMatrixJob reads from the ComponentTypeHandle TransformToMatrixJob.JobData.__Unity_Transforms_LocalToWorldTransformTypeHandle. You are trying to schedule a new job SpawnZombieJob, which writes to the same ComponentTypeHandle (via SpawnZombieJob.JobData.__Assets_Scripts_ComponentsAndTags_GraveyardAspectTypeHandle._transformAspect.m_LocalToWorldTransformCth). To guarantee safety, you must include TransformToMatrixSystem:TransformToMatrixJob as a dependency of the newly scheduled job.
The blog post I have linked in the description of the video fixes all breaking changes since this version was released. Good question on the baker, you can think of it as one of those "magic" things with Unity ECS that Unity just automatically uses for us and we don't need to manually call ourselves. Similar to how we just create Systems, but don't directly call them, they just automatically run on entities with the specified input components. The baker's job is to just take data we set in the editor and use that to create an entity. By being on an object in a subscene, this baking system is automatically ran to convert that GameObject into an entity.
@@TurboMakesGames thanks! I'll check it out. I would like to get explanation along with examples. Sometimes it's not enough in the video. I did not find proper way to organize hierarchy of entity. Like I have auto turret that should find target, then head should be turned to that target. The question is how have reference to LocalTransform of the head from the root turret object. I can put everything in head of course, but there are other cases when I need hierarchy and references to children. Can you give me some links to where I can understand that?
Great video! I do have one question that I can't get around in the past 2-3 days. My player controller is currently written using mono-behaviors. Is there a way to translate his position in ECS and then access it from another system? Simplified question: Player in mono-behavior, enemies are ECS. I want enemies to follow player's position. Thank you in advance
Probably the best way to go about doing that is to have an ECS "data-only" entity of your player, then use a MonoBehaviour to update the position of that player entity every frame, then all your enemies could easily follow the player entity position. Hope that helps!
I've been wondering how we're supposed to do initialization in systems which are not ready at game startup. I see you used OnUpdate and then just set enabled to false. Is this the standard way of handling this use case? It's a bit awkward compared to gameobjects where the lifecycle begins when the object is spawned rather than always at game startup (or when the world begins). I'm trying to build a component with data which will not be known until runtime, so I guess a baker will not work. Not sure the best way to do this, but I've been doing it in a monobehaviour with entitymanager once the data is ready. It just doesn't seem like a good way to do handle things.
The MonoBehaviour approach should be fine as it likely wouldn't be happening frequently. Another approach you could take is to create a system that runs logic during the OnStartRunning phase and set the system to only run when entities of a certain query match it - just be sure to modify the archetype of the entity during this step so the system stops running; this means that the next time an entity matching that query is spawned, the initialization system will run again. Hope that helps!
Thanks! I had fun making it 😊 Good to know you'd like to learn some more about saving and loading as that is definitely an important topic. What do you mean when you say you are doing saving and loading the "traditional way?"
@@TurboMakesGames As far as I know, doing saving and loading in ECS need to de-seriallize and serialize the whole world. But what I did is just to copy data from "entities" which I want to save and when loading game, I paste the data back to the "entities". For example, I have an inventory entity, which is a dynamic buffer. So, I copy the dynamic buffer into array in a class and save the class. When loading, I get the array from the saved class and put the data back to the dynamic array. Overall, I did nothing about the "world". This is what I think the "traditional way". But, it seems this way does not work after building the build. I am not sure why. Try to figure out...... Anyway, I am new in programming, so I am sure there is something wrong somewhere in my code. But to find out which code causes the problem, I have to re-do the whole project and test bit by bit....that is the only way I can think of (or I do the reverse, comment out bit by bit)...because in unity everything works fine, but not in build. That is frustrating! at the end, if I need to re-do, i must as well learn the new 1.0. Hence, here I am, learning from your video :)
Hi! Thanks for the video! I was trying to follow using Unity 2022.2.7f1 and as soon as I add a private readonly RefRW to the graveyard aspect (AlienSpawnPoints in my project) I get errors on playmode: The ComponentTypeHandle SpawnAlienJob.JobData.__AlienRun_ManagerAspectTypeHandle.ManagerAspect_alienSpawnPointsCAc can not be accessed. Nested native containers are illegal in jobs.
Don't think you have to. But its pretty optimal. And why do ECs if your not after the utter most performance. And this way you get the same "map" generation as long as you use the same value for seed
thanks a lot for your tutorials they are the best. Is it possible to make Visual Studio add the references at the top "using.." automatically as you type something?
Hey TMG, I was wondering what happens to the collider when you put a GO inside a SubScene without removing the collider. Does it work as hybrid ECS + GO?
The GameObject and collider would be converted into an ECS entity and ECS compatible collider. The regular Unity collider acts as an authoring component for the ECS collider in that case
If I'm starting to learn Unity from scratch, should I just wait for ECS and DOTS and forget about all the Unity Object Oriented courses and lessens out there? Really hope you can makes this an entire series to those of us who find DOD confusing.
If you're starting out, I'd highly recommend using GameObjects in the traditional Object-Oriented style. The OOP workflows aren't going anywhere anytime soon and as of now DOTS is really for those who are running into the upper limits of what traditional Unity can do. All the best with your game dev journey!
UPDATE April 2023: Since I posted this original video, there have been a number of breaking changes in the latest version of the ECS API. While the main concepts are all still the same, the implementation details are slightly different. As such, I've created an article detailing these changes that you can reference as you go along: www.tmg.dev/tuts/zombieupdate/
I came just here to post link. Keep it up man (Y)
Will you be doing a new bigger video now that 2022 LTS is out? Huge fan very excited for a definitive video on the subject
Fully appreciate the update. Thank you so much.
legend
I finally decided today was the day I was going to learn ECS, but it's disappointing to see all the things that have changed since this video was made a year ago. I get a video like this is an undertaking, but before I get started trying to sort-out the changes, I just want to make sure...you're not planning an update if I wait a week or two, are you?
Thank you for this tutorial! Although I have been using Unity for a while now ECS is still pretty daunting to me. I find that DOTS get very technical very quickly so videos like these are a huge help for quickly getting me to a point where I can start to experiment with game mechanics (instead of me struggling to figure out how to structure my code, what classes to use, etc).
I'm hoping you'll turn this into a series in which you build popular game mechanics, but with DOTS/ECS (like you've done on smaller scale in the past but for 1.0). I think that's something that'll really help more people hop on the DOTS/ECS train. Since the Unity team doesn't seem to care to do this themselves it is up to the community and you're doing a fantastic job.
Thank you so much for the support Arveus!! Really great to hear these kinds of videos are helpful to you to get you up and running with a working knowledge of these concepts.
Really appreciate the feedback too - those are definitely some things I'd like to do and have some cool ideas for videos along those lines. All the best!
hmmm... i think they don't have official tutorial videos yet because their DOTS are still experimental... so things are still changing
I second that. Also, a very cool way to keep the video relevant is to release that blogpost with notes of what changed. Keep it up!
Thank you for your incredibly helpful content! Much appreciated
Thank you so much for the support! Very glad to know this has been helpful to you 😊
If you aren't seeing entities in the Scene View but you can still see them in the Game View - open the Preferences window (Edit > Preferences...) then on the Entities section, make sure "Scene View Mode" is set to "Runtime Data" not "Authoring Data"
I have vica versa :)) I was following CodeMonkey's tut, my entities position is updating, but capsula stays still. Entity has capsula as a child. Also I can see capsula in Scene view and in Main Camera small window (when i select Camera in hierarchy), but i don't see it in Game window :( where cound be the issue?
Thank you~ was looking for this!
thank you very much!
aaa thank youuu!
Always appreciate it when turbo makes an ECS tutorial
Thank you so much Thành - I really appreciate the support 😊
Just letting everyone know at 1:02:00 UniformScaleTransform is no longer there. Replace it with LocalTransform, which contains all the same fields.
thanks!
What versions are you on? Because I'm using UniformScaleTransform and it's working fine. (Unity 2022.2.0b16, Entities 1.0.0-exp.12)
@@envilonscript I'm on exp. 1.0.0 exp.15,
Thanks, I just bumped into this!
I was just looking around for 10minutes and thought "Hey maybe someone commented something"
Thank you for being that guy, saved me some trouble.
Cheers!🍻
i took now 4 days fulltime and worked trough your tutorial and now got my own "game" to expand on it, thank you so much, wouldnt had been able to learn and progress so far with just unitys documentation or get here at all
Congratulations that is so great to hear!! Feel free to share what you're working on over on our Discord if you'd like - tmg.dev/Discord
Duuude, thanks for being one of the only quality up to date DOTS resources. Its rough to have to navigate through so many legacy systems and depreciated concepts when trying to do simple tasks.
So glad to hear these videos are helpful to streamline all the craziness 😁
This is the clearest and most comprehensive tutorial to DOTS I found. Thank you for making this!
Unity really should hire you to promote DOTS, because you're doing fantastic job!
I feel like Unity is finally on a way to create something beautiful and really powerful with DOTS, because I, personally, see huge potential in it
True
Thank you so much for the kind words! I think they've really got something good with DOTS so happy to spread the word how I can 😊
@@TurboMakesGames you are doing a great work!
Yey, the fresh tutorial! No need to get stressed about outdated information, everything is happening right now!
Things are coming together!! Enjoy 😊
Following along with the tutorial.... At 39:11 when I set the inspector to "run-time" with the yellow circle, it just says "Invalid Entity The entity does not exist anymore, please unlock inspector if it is locked or re-select." The inspector info for the brains object shows but not for the tombstone. I guess it's not baking for some reason? Anyone else getting this problem? The Inspector is unlocked and I have re-selected even re-created the object and the pre-fab that gets attached to it trying to troubleshoot.
Really love your ECS videos Johnny. Clear, concise, practical examples, and a little nerd humour .... love it man. Keep up the great work brother. We appreciate you man.
If this isn't an official supplement to the Unity documentation, it should be. Thanks for this great learning resource!
Thank you so much for the support and the kind words 😀
This is an awesome video. You managed to cover pretty much all features within a self-contained game project. Solid dedication.
Thank you so much Damian!! See you at Unite if you'll be at the MTL office tomorrow 😊
Amazing job on this, Johnny! I just finished the Spawning Zombies section and a minor change that I had to make was scheduling the SpawnZombieJob rather than running it on the main thread. Without doing that, it was producing an error associated with a scheduling dependency conflict with TransformToMatrixSystem:TransformToMatrixJob to access LocalToWorldTransform. I'm using the just-released Unity 2022.2.0b13 and the EntitiesGraphics 1.0.0-exp.14.
Yeah that must have just been a roll of the dice about how your systems got ordered vs. how mine were. Yes, scheduling the job would appropriately account for any dependencies so that is an adequate solution 👍
@@TurboMakesGames Ah, and your new video on Systems covered that perfectly! 😀
Thanks this helped me, had the same issue
I appreciate you mentioning that ECS is not very beginner friendly for people new to C# and Unity. I thought I was just dumb for not understanding any of the ECS information I was trying to absorb in other tutorials, but now I realize that they're made for someone with more experience.
Finally a good explanation of ECS, DOD, and why I should care.
As a UE dev I was struggling on why this mattered from everyone else. Thanks!
Awesome, glad to know you found this helpful. All the best with your projects!
My man. I found your channel from Code Monkeys and what a joy this is. You are fantastic the way you talk, explain things, the details, quite direct on the case and no gibberish in between. You and Code Monkeys are my go to for Unity hands down!
Keep up the good work, I am subscribing ;)
Thank you so much for the kind words, glad to hear these videos have been so helpful to you 😊
Not sure if I'm making a mistake or if something broke with the new LTS or ECS versions, but at 29:37 you add a gameobject to the sub scene and hit play and it displays as an entity. When I do that, the inspector just says it's an Invalid Entity.
same dude
same
From all Unity-related content around ECS, this is the one video I was waiting for. Thank you, Turbo
Awesome, hope it lives up to the hype 😁
Ok. This earned my subscription. I don't know anyone else doing stuff like this. I'm hoping ECS really comes into its own, ready and raring to go for when I start the project I think could really use it.
Right on - I'm very excited for the future of ECS as well 😀
Thanks!
Thanks so much for the support William! Enjoy the video ☺️
Thanks!
Thank you so much for the support!!
Covering the breaking changes including the recent revision article has been incredibly helpful. Tracking changes for Unity DOTS over the past few years has been a nightmare to get a firm grip on
Great to hear it!! Hopefully my future videos won't require any major patches as the API solidifies 😁
@@TurboMakesGames You've helped me so much so thank you
GET IN
Ive been waiting for Unity to finally bring out 1.0 Dotty!! Nice to see its finally out!
Love the enthusiasm!! Enjoy it 😀
If you still get InvalidOperationExceptions after adding the [UpdateAfter(typeof(SpawnZombieSystem))] in 1:36:36, I also had to add [UpdateBefore(typeof(TransformSystemGroup))] to the ZombieRiseSystem to resolve this issue.
This. Thank you very much. I did " state.CompleteDependency();" on SpawnZombieSystem.OnUpdate and it also "fixed" it but im assuming that without your approach, Rise job may run through another update tick, at least its the reasoning i can find about this error... Weird that Turbo didn't have this issue nor specified in the update thread...
Thank you so much! Was getting crazy trying to understand why I had the issue, this comment should be way higher..!
Thank you so much! If you can explain why this is occuring and why this attribute solve this problem that would be great!
Thank you! I can't start following along immediately because I'm about two thirds of the way through the 0.51 tutorial (which is brilliant by the way!), but very keen to work through it after.
Cool - hope the 0.51 video gave you some good exposure to the concepts and that it'll give you an appreciation for all the awesome new features in 1.0 😊
If your entities are not visible in Scene View but visible in Game View, open the Preferences window (Edit > Preferences…) then on the Entities section, make sure “Scene View Mode” is set to “Runtime Data” not "Authoring Data".
This was great, Turbo. Thanks for this. Some videos I just want to thumbs up more than once, this is one of them.
Haha thank you so much! So glad this video was helpful to you 😀
I am very grateful to you for this amazing video. I really learned a lot of things from it. I fully share your admiration for Unity DOTS and look forward to a full commercial launch. Thank you for all the hard work you put into this video
Thanks for the kind words, all the best with your projects!!
After finishing and implementing the whole video, this was really hardcore tutorial and full of information, but also very clean to follow along. Great job! Looking forward to more things like how to use NavMesh, physics, new Input system and animations with dots.
Awesome - so glad to hear this! Definitely want to get into more fun/complex topics now that this one is out there for people to reference 😊
For only moving after rising around 1:51:58 I think it would be better to use without the RiseSpeed component since you remove that after rising. This saves you from having to remove and add components. Still great video though, thank you.
Hi! I'm new to ECS and following your tutorial which helps a lot.
Following your video, I've got one question.
(1:00:27) You set system's state to OnUpdate to wait until GraveyardProperties Singleton exists so that no reference error occurs.
My question is, if you have to implement some method using OnUpdate function in same class, what will you do?
Will you be able to easily implement it,
or there is no way to guarantee singleton returned before OnCreate is called so you have to seperate GenerateSystem/LogicSystem unreluctantly, not to fulfill the responsibility of class?
I mean, is there proper way to 'await' return of singleton class(and delay call of update) so that you do not need to implement generating process in update method.
I'm wandering if ECS system having Awake/Start seperated would made this easier since we could simply secure singleton instance in awake and call it later in start or update in traditional unity system.
Looking forward to your answer! Thanks in advance! (sorry for my short English, please be gentle if my sentences looked silly or rude)
You mean like a "RequireForOnCreate"? That would be really nice, but I am not aware of something like that for now.
Thanks for the tutorial! I really love it. Subscribed and bell on!
I'm using Dots 1.0.0-pre.15 with Unity version 2022.2.0f1
I gather some issues that I found and share for who have problems like me. Notify me if any was wrong. :)
1. Change all UniformScaleTransform to LocalTransform, then -> ecb.SetComponent(newTombstone, newTombstoneTransform);
You do not need to instantiate LocalToWorldTransform or LocalTransform. Just pass the variable in ecb.SetComponent().
2. Error: "Loading Entity Scene failed because the entity header file couldn't be resolved. This might be caused by a failed import of the entity scene. Please take a look at the SubScene MonoBehaviour that references this scene or at the asset import worker log in A:\xxxxxx\ZombieBrainHunter-DOTS\Logs. scenePath=Assets/Scenes/GraveyardScene/GraveyardEntityScene.unity"
Fix no.1: Add [ChunkSerializable] property for ZombieSpawnPoints script. (I got a message that unity told me to do for avoid this error)
Fix no.2: Duplicate your objects in sub-scene and delete the old objects.
3. You might need to change trasformAspect.Position (Obsolete) to transformAspect.WorldPosition instead. Rotation as well
But on ZombieRiseAspect, you might use .LocalPosition instead. I don't know why .WorldPosition make my zombies rise up from center of the world position.
4. Use [EntityIndexInQuery] instead of [EntityInQueryIndex]
5. If you try to get brain scale or get transform component
Fix: Change GetComponent to GetComponent() after called you can just .Scale
6. Error:"InvalidOperationException: System.InvalidOperationException: GetSingleton() requires that exactly one entity exists that matches this query, but there are {0}.
This Exception was thrown from a function compiled with Burst, which has limited exception support."
Fix: Add state.RequireForUpdate(); in OnCreated() but if you on SystemBase you can cut "state." out and then RequireForUpdate();
@turbo makes games Can you pin this comment please ? :)
This comment should be pinned
2:24:30 staring at the brain as camera moves, and then switch to another static window gives me a trip
Most helpful refresher. Thank you.
Glad it was helpful!
1:34:25, It's confusing
You created ZombieRiseJob struct, but didn't pass any ZombieRiseAspects (as it needs in Execute function)
I thought there should be some SystemAPI queries to get all necessary data like aspects and components and pass through some worker thread (for example using Ijobs in your video)
How does IjobEntity struct know there should be a ZombieRiseAspect? Is it the way how Aspects work in DOTS? Is it so that aspects need no queries in order to get them?
Figured out myself, the IJobEntity interface, which is used here, already includes queries within for all entities and... seems like aspects as well
impressive, thanks man, this video has everything I'm trying to learn in this moment
I'm done watching the whole video and it's interesting to know that you were recording for ~6 hours and then the final product is 2 hours and 27 minutes 😯, nice...
and it seems that you know what you are talking about.. plus your code seems like well made so i'm really enjoying it especially to know more about ECS in Unity or in other words the Data-Oriented design... i'm a beginner so i'm just passing by right now in video about game developing then after watching them i am gonna go to pure C# programming...
Planning to settle in and watch this over the weekend. 🤓
Right on - hope you enjoyed 😀
LOVE - I'm gonna follow this through!
Awesome - hope you enjoy!!
Great practical video about ECS. Thanks
Sure thing, glad it helped!!
Amazing tutorial. Thank you very much! So many topics covered, and we get a complete working project in the end It would have taken me months to learn and get everything covered in this video working myself by just using the official docs.
At 1:21:46 is there any particular reason to use a job, instead of directly decreasing the timer and spawning zombies in the OnUpdate function? Especially since we use Run(), which means that it's executed immediately in the main thread, I don't understand why it must be a job. Maybe my understanding is flawed? Appreciate if someone clarifies it for me
Thanks. This helped me to build my first ECS for a test task. Now I see this might be quite a tool, especially it's pre-release now.
Thanks for the video a lot, one issue I have while following along is, I cannot see the IAspect which I created in the Aspects inspector in the play mode.
Bump, got the same issue
@@Heisenberg-xc8ub just to give info, even though it didn't show up in the aspecs section, my code works, system is able to retrieve the correct entities with that aspect.
How interesting - maybe just make sure you are in the "full entity mode" in the inspector rather than the hybrid mode? That would be the little orange circle is full rather than empty or partially full in the upper right. Glad to hear that it still works fine though!
@@TurboMakesGames Unfortunately it doesn't show with full entity mode too. Maybe just a bug regression on the editor with the new minor version.
@@hakanviajando Same issue for me in 2022.2.b13, anyway, since you say it works in code later at least I won't need to bash my head anymore trying to figure out if I did something wrong. Thanks.
Thank you for the effort, really useful video! I can't say I like the extra layers of complexity that entities 1.0 brings, but I guess that's because I prefer a code-only solution, and most of these seems to be implemented to get a better integration in the editor.
Glad you enjoyed the video. Fair enough - though thinking about it from Unity's perspective they need to have strong editor integration as production ready games will often have non-programmers working in the editor
Really great video as usual. Was the perfect video to get back into ECS after a longer break.
I am running into some issue actually, which might be a very basic problem. Whenever I hit play, I can only see tombstones and Zombies in the game view but not the scene view. This is for both beta11 and beta13. Not sure if anyone has encountered this issue, but I'd appreciate if people who have encountered it before might be able to help.
This is only for Entities spawned and does not affect other Gameobjects in the subscene.
Found the issue. I didn't set Preferences -> Entities -> Scene View Mode to Runtime Data
Boom - you got it! Forgot to mention that one in the video 🙃
Amazing! Should pin this.
@@JonasSchett Thank you. I was closing the Subscene in order to see them in editor. Also its no renamed to Scene View Mode = Runtime | Authoring Data. No transform handle, but guess we dont need that omg
Nicely done man !!!!
Thanks Yu!! Glad you though so 😊
YESSSSSSSSSS
Love the hype!!!! Enjoy 😊
Man thank you! I am already in the game industry, working in a game company and trying to improve my skills by learning the ECS. There is no other tutorial better than yours. :)
I have a question: We have the zombie rise aspect and the local transform reference in it. So to my understanding; each entity has its own aspect because we can move them seperately or is there one for all zombie entities or is there one for all entities? I am not sure that I have understand the aspect concept fully.
To what I understood, aspects creation and assignation is all done under the hood.
Every entites, that have all the components referenced on an aspect, have that aspect on them. You can look at the aspects of an entity in the Aspects Tab in the inspector in runtime mode.
I may be wrong but it's what I understood after using them a bit 😁
Are you going to do a video on the new animation package? Would love to understand actual skeletal animation in dots. Also how does the rigging package fit in? And how does the playable API actually work? Every video I've found that is just about timeline, but it does so much more than that but I can't figure it out.
What animation package are you referring to? As of now, Unity doesn't have an officially supported animation solution for DOTS. However there are some other options available to you - forum.unity.com/threads/dots-animation-options-wiki.1339196/
Question : Why not put the initialization inside the public void OnCreate() function instead of OnUpdate? Is there a reasy why?
Thank you for this great DOTS tutorial ! Aspects seems to be removed in futur version. Could you plan to update your website to manage this change ?
Very nice tutorial! Thanks!
Glad it helped you, all the best with your ECS learning 😊
The ZombieRiseSystem where you removed components (1:42:58) ran 5x slower than before (1:39:12). Why's that? Could it be because removing components is slow?
Removing components does take time, but it doesn't happen often so that's probably not why. I'd say it's more likely because of the other changes with the job like the parallel stuff.
Good observation - that is really interesting. My hunch would be that this increase is from getting the ECB singleton and creating the command buffer as this job just schedules the removal commands, not execute them. But I'd have to do some more testing to be certain.
Is there a specific reason why we create a NativeList just to use the ToArray() method on it in SpawnTombstoneSystem? Wouldn't it be better to directly create a NativeArray and avoid the ToArray() call?
Cảm ơn bạn!
Thank you so much for the support Nguyen!!
Thanks for this turtorial! I really learned a lot of things from it. Besides, I'm confused about how to play animations and how to prevent objects overlapping. Would you plan to add these systems?
Glad it was helpful! ECS doesn't have a native animation solution yet, so you can either sync the entity with a GameObject for the visuals or use a 3rd party solution. The Unity forums has a DOTS animation section where someone has a post listing all the options. Preventing overlapping gets a bit more involved as you'll have to implement DOTS physics or build a custom avoidance solution. But this is something I'd like to cover at some point
Are there any changes in the way to change the materials settings of a single Entity (made from a prefab via a baker)? Or can I check your video about Material Overrides?
Material property overrides would probably be your best bet. Without getting into too much detail there are some efficiencies through using material property overrides without switching materials for an entity.
@@TurboMakesGames cool, then I'll check out your video about this. I hope it's not too outdated since the 1.0exp update?
Fantastic Explanations!
Hey Turbo. Been watching some/most of your ECS videos as they are definitely the top and go to resource for learning Unity DOTS in my opinion, but excuse me if I've missed one where you explain my following question. I've been trying to get a grasp on how 2D rendering works with Unity ECS outside of project tiny which seems abandoned at this point. I've seen some repos with custom Game Object to Entity Sprite Rendering conversions and I see that Unity ECS also now supports that conversion in subscenes. However from the limited understanding I still have of DOTS, I understand that sprites are still stored as reference types and thus can't be bursted.
My question is, do you know what way or ways even, for working efficiently with 2D in Unity. My test case I want to make is a simple 2D platformer with # amount of entities, but I feel a bit blocked/gated by the lack of focus on 2D in Unity ECS. Can an image, say 16x16 pixel tile be stored as data/struct in e.g bytes with read/write access and have a system render said tile?
I would greatly appreciate if you could give your insights on this or perhaps send me in the right direction. (Bonus subjects: 2D animation, 2D lights and tilemap in ECS).
I love your videos, thanks for making such great content!
Hey there, thanks for the kind words and glad to hear these videos have been helpful to you!! Yes, so Project Tiny (now referred to as DOTS runtime) is on a development hold until after production-ready 1.0 is out. Right now, probably your best bet for 2D would be to render textures to a quad mesh. Though I will likely be chatting with some DOTS people at Unite next week so I'll see if I can get any insight from them on recommendations
I was thinking about the ZombieEatSystem. Do you know how the concurrency of EntityCommandBuffer.ParallelWriter is implemented? I would guess it is implemented with locks (but maybe that sortKey does some magic?). If that is true, then we could skip the ApplyBrainDamageSystem and just put a lock around the health of the brain directly instead.
Another alternative would be to just not run the eating in parallel at all, as I suspect lock contention would take up the majority of the time of the eat code anyway. But maybe later we want to add more juice there, and it might be worth parallelizing again. Does Unity ECS ever do task level parallelism? as in, can it run two systems in parallel? If so, we could run the eat system sequentially but at the same time as some other system, that makes use of the rest of the cores/threads.
Lastly, we could instead tally up the damage per thread, and then sum all damage that each thread accumulated. Whether this would be good or not depends on how many threads Unity spawns for these jobs. Do you know how it works here? Does Unity try to match threads with number of cores (or something like that), or does it have lots of threads decoupled from core count?
Thanks in advance. :)
Thanks for the thoughtful comment. Unity takes care of a lot of the messy details though job dependencies and other safety checks. Though if you know what you are doing and you know you are writing to different places in memory from multiple threads, Unity does give you some tools to bypass their safety checks and other parallel restrictions - though showcasing those things would be far outside the scope of this video. "Systems" themselves can't run in parallel as they all run on the main thread - though systems often schedule jobs that run on worker threads and these jobs can all run in parallel, should they not have any overlapping dependencies. By default, Unity will assign one thread as the main thread and al the remaining threads on the CPU will be designated as worker threads. Any available worker thread can pull jobs from the queue for processing. Hope that helps!
@@TurboMakesGames Alright, awesome! Thank you very much :)
Thanks for the video! I wonder if its worth going to DOTS if youre already building on top of Job System/Burst, from the optimization and possibilities perspective
Probably not. Unity was a leader in high fidelity cell phone games long before DOTS, so if you are already optimizing to the point of using jobs/burst, you're probably so cognizant of optimization that you likely have bigger bottlenecks elsewhere.
Of course it all depends on your project. If you are dealing with 10,000s of dynamic objects, it could def help.
Technically speaking jobs/burst standalone are still considered "DOTS." If you are referring to ECS, then there are certain applications where switching to ECS would benefit. You can make a lot of things when starting with ECS, but switching to it is generally only a good idea for very specific use cases.
Great video, although I am stuck at the UniformScaleTransform. Rider doesn't find the type and I've been looking but can't locate it either. Where is it defined? I am using Unity.Entities and Unity.Transforms in the GraveyardAspect.cs. Or has the name changed in 2022.2.0f1?
Then when you set component to newTombstone
ecb.SetComponent(newTombstone, newTombstoneTransform);
This work for me (I'm using 2022.2.0f1)
There were some changes to the Transform API since this video was published. Try using LocalTransform instead
Thank you! Great work!
Thanks! Glad you liked it 😊
Thank you for your videos, you are making a good public service
Appreciate the support 😀
1:25:27 -- getting this fun error: InvalidOperationException: The ComponentTypeHandle SpawnZombieJob.JobData.__DotsTutorial_Zombies_GraveyardAspectTypeHandle.GraveyardAspect__zombieSpawnPointsCAc can not be accessed. Nested native containers are illegal in jobs.
The error goes away if I remove the "new SpawnZombieJob{}.Run()" block from OnUpdate. The error remains if I instead comment out everything in the Execute(GraveyardAspect aspect) function in SpawnZombieJob. The error also goes away when i remove any reference to the ZombieSpawnPoints object inside of GraveyardAspect. Is there some issue to be wary of when using a NativeArray inside a job?
Unity 2022.2.5f1. Entities 1.0.0-pre.44.
SAME 🙏 (2022.2.6f1)
update :
I removed the job and put everything in OnUpdate
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var deltaTime = SystemAPI.Time.DeltaTime;
var ecbSingleton = SystemAPI.GetSingleton();
var graveyardEntity = SystemAPI.GetSingletonEntity();
var graveyard = SystemAPI.GetAspectRW(graveyardEntity);
var ECB = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged);
graveyard.ZombieSpawnTimer -= deltaTime;
if (!graveyard.TimeToSpawnZombie) return;
graveyard.ZombieSpawnTimer = graveyard.ZombieSpawnRate;
var newZombie = ECB.Instantiate(graveyard.ZombiePrefab);
}
May be stupid but seems to work
@@stonbax yeah my thinking, too. Or use UnsafeList for all of these operations (the only alternative I've seen so far, but idk how to implement it well and whether it it is a good idea in the first place)
@@uberjuice9438 UnsafeList works for me. Thanks for the suggestion!
your videos are pure gold, thanks
So glad to hear they've been helpful to you!
This is an Amazing Video. 👏🏻👍🏻
Thank You.
So glad to hear you think so!!
gave up on creating GraveyardAspect. In unity 2023 several functions are already obsolete, and IAspect requires different implementation than in the video
Thank you for the tut! One question, what's the best way to handle passing back data to mono space? Say you wanted to keep track of the Brain Health in a UI?
Thanks for the effort making this🙏🏻
Absolutely, glad you found it helpful!
I am marking a spot, survived 1h52minutes. That's too much for me. So much code for such a simple mechanic that I don't think I am going to implement it into my project, at least not yet. Looking at your new GDC video - I am hoping for the Rider integration at least.
Video was great. Much respect. As the other dude says, in the second half you got so fast that I couldn't keep up and had to rewind the video all the time. No worries though, probably the best guide on RUclips for starters.
Let's hope it does get simpler in future.
Nice almost 2hrs in, that's good! Definitely a lot all at once if you aren't familiar. Thanks for the feedback though, will certainly keep it in mind for future tutorials like this one
I was so hopeful watching this video, but sadly it seems as if the vast majority of it is out of date. Your update page doesn't even address all the inconsistencies that now exist. For instance, ISystem doesn't appear to have any members to implement. Is there an updated video you recommend?
Hey sorry to hear you've been running into some issues like that - for ISystem, there are now default implementations of the OnCreate, OnUpdate, and OnDestroy methods so you don't need to define the lifecycle methods you don't need, so you'll have to manually type them (or use an IDE template/macro to automate some of this for you). I don't know of a recent full project video, but I would highly recommend checking out the Unity ECS sample projects, they are a fantastic learning resource. github.com/Unity-Technologies/EntityComponentSystemSamples
I will be doing a full project video with Netcode for Entities soon which will show all the latest API, however I'd recommend having some familiarity with ECS before that. In the meantime, let me know if there are any other issues you are running into! Or ask our Discord community - tmg.dev/Discord
All the best!
Did they simplify dots or there are still too many unnecessary steps to achieve the same goal?
Do you have any tutorials over netcode and AR Foundation, particularly in ArCore?
I do not, don't necessarily have any plans anytime soon either. Possibly something on Netcode for Entities at some point
great tutorial!
Hey man, amazing job you did there! I was going to ask, how hard is possible to implement animation for like idle, attack, running type of things in ECS?
Unfortunately, there isn't an ECS compatible animation solution from Unity but it is still part of the "Planned" section of the DOTS roadmap. Check out this forum post by a community member talking about some of the options for animations in DOTS available now - forum.unity.com/threads/dots-animation-options-wiki.1339196/
@@TurboMakesGames Thank you!
You never explain what IAspect or Aspects are and I'm now very confused. 46:38
You are better than Brackey!! I am adding your picture to my alter next to his.
Wow, it was amazing, I just didn't get - what is the point to have "Aspect"?
Glad you enjoyed!! - Good question (I do plan on making an in-depth video on these later) but the main idea is so that multiple data components can be accessed through one single Aspect. In the past we needed to declare all the data components we needed and access each of them individually, which ended up leading to really messy systems. Putting the helper functions inside aspects further helps remove code from systems and put it in a place that makes more sense.
很喜欢你的教程,我是来自中国的一名Unity开发者,国内没有这么成熟的教程供我们学习,谢谢你的分享!😘
Cheers! Glad this was helpful to you - all the best with your future learning of ECS 😊
@@TurboMakesGames But now I have a problem. Now I can generate tombstones randomly, and tombstones of random size. Why can't I see tombstones in my Scene window? It can only be seen from the Game window. We look forward to your reply. Thank you!
@@Orange_-pp9nh You may just need to change your view settings for the scene view - open the Preferences window (Edit > Preferences...) then on the Entities section, make sure "Scene View Mode" is set to "Runtime Data" not "Authoring Data"
Hope that helps!
@@TurboMakesGames All right Thanks!!
@@TurboMakesGames Hello, I followed your tutorial to the time of 1:25:19, and then I ran. The zombie did not appear, but a bug appeared. The prompt message is:InvalidOperationException: The previously scheduled job TransformToMatrixSystem:TransformToMatrixJob reads from the ComponentTypeHandle TransformToMatrixJob.JobData.__Unity_Transforms_LocalToWorldTransformTypeHandle. You are trying to schedule a new job SpawnZombieJob, which writes to the same ComponentTypeHandle (via SpawnZombieJob.JobData.__Assets_Scripts_ComponentsAndTags_GraveyardAspectTypeHandle._transformAspect.m_LocalToWorldTransformCth). To guarantee safety, you must include TransformToMatrixSystem:TransformToMatrixJob as a dependency of the newly scheduled job.
I would love to see a video dedicated to system design. Something that isn't a toy example, where I can see my own creativity coming alive.
Awesome, glad to know you'd be interested in that sort of thing - that sounds like a ton of fun. Open to more specific ideas if you have any 😊
So, I'm gonna go ahead and watch that whole thing :)
Love it!! Enjoy
Any plans to update it to Entities 1.0.11?
I don't get where your Graveyard Baker is called? Because you put your MonoBehaviour under Subscene?
The blog post I have linked in the description of the video fixes all breaking changes since this version was released.
Good question on the baker, you can think of it as one of those "magic" things with Unity ECS that Unity just automatically uses for us and we don't need to manually call ourselves. Similar to how we just create Systems, but don't directly call them, they just automatically run on entities with the specified input components. The baker's job is to just take data we set in the editor and use that to create an entity. By being on an object in a subscene, this baking system is automatically ran to convert that GameObject into an entity.
@@TurboMakesGames thanks! I'll check it out. I would like to get explanation along with examples. Sometimes it's not enough in the video.
I did not find proper way to organize hierarchy of entity. Like I have auto turret that should find target, then head should be turned to that target. The question is how have reference to LocalTransform of the head from the root turret object.
I can put everything in head of course, but there are other cases when I need hierarchy and references to children.
Can you give me some links to where I can understand that?
Great video! I do have one question that I can't get around in the past 2-3 days. My player controller is currently written using mono-behaviors. Is there a way to translate his position in ECS and then access it from another system? Simplified question: Player in mono-behavior, enemies are ECS. I want enemies to follow player's position. Thank you in advance
Probably the best way to go about doing that is to have an ECS "data-only" entity of your player, then use a MonoBehaviour to update the position of that player entity every frame, then all your enemies could easily follow the player entity position. Hope that helps!
Thank you for your work!
I've been wondering how we're supposed to do initialization in systems which are not ready at game startup. I see you used OnUpdate and then just set enabled to false. Is this the standard way of handling this use case? It's a bit awkward compared to gameobjects where the lifecycle begins when the object is spawned rather than always at game startup (or when the world begins).
I'm trying to build a component with data which will not be known until runtime, so I guess a baker will not work. Not sure the best way to do this, but I've been doing it in a monobehaviour with entitymanager once the data is ready. It just doesn't seem like a good way to do handle things.
The MonoBehaviour approach should be fine as it likely wouldn't be happening frequently. Another approach you could take is to create a system that runs logic during the OnStartRunning phase and set the system to only run when entities of a certain query match it - just be sure to modify the archetype of the entity during this step so the system stops running; this means that the next time an entity matching that query is spawned, the initialization system will run again. Hope that helps!
@@TurboMakesGames was not aware of onstartrunning. That's exactly what I needed. Thx
The best video ever. It would be great to see how to do saving and loading in ECS also!
I am still doing my save-load in a traditional way. :(
Thanks! I had fun making it 😊
Good to know you'd like to learn some more about saving and loading as that is definitely an important topic. What do you mean when you say you are doing saving and loading the "traditional way?"
@@TurboMakesGames As far as I know, doing saving and loading in ECS need to de-seriallize and serialize the whole world. But what I did is just to copy data from "entities" which I want to save and when loading game, I paste the data back to the "entities". For example, I have an inventory entity, which is a dynamic buffer. So, I copy the dynamic buffer into array in a class and save the class. When loading, I get the array from the saved class and put the data back to the dynamic array.
Overall, I did nothing about the "world". This is what I think the "traditional way". But, it seems this way does not work after building the build. I am not sure why. Try to figure out......
Anyway, I am new in programming, so I am sure there is something wrong somewhere in my code. But to find out which code causes the problem, I have to re-do the whole project and test bit by bit....that is the only way I can think of (or I do the reverse, comment out bit by bit)...because in unity everything works fine, but not in build. That is frustrating!
at the end, if I need to re-do, i must as well learn the new 1.0. Hence, here I am, learning from your video :)
Hi! Thanks for the video!
I was trying to follow using Unity 2022.2.7f1 and as soon as I add a private readonly RefRW to the graveyard aspect (AlienSpawnPoints in my project) I get errors on playmode:
The ComponentTypeHandle SpawnAlienJob.JobData.__AlienRun_ManagerAspectTypeHandle.ManagerAspect_alienSpawnPointsCAc can not be accessed. Nested native containers are illegal in jobs.
Same here, I've been playing around with it and it just doesn't like IComponentData with a NativeArray
It's fine with just adding the ZombieSpawnPoints component in the baker, but errors on each update when trying to access it through the IAspect
Thanks for the video! How did you make TMG.Zombies namespace by default when creating new scripts in Rider?
Edit -> Project Settings -> Editor -> Root Namespace = "TMG.Zombies"
I'm confused. Do I have to create an entire class for a random property?
Don't think you have to. But its pretty optimal. And why do ECs if your not after the utter most performance. And this way you get the same "map" generation as long as you use the same value for seed
Is it possible to call Animator.Triggers from ESC System?
Yes - you'd have to do this from a SystemBase system and it couldn't be inside a job.
thanks a lot for your tutorials they are the best.
Is it possible to make Visual Studio add the references at the top "using.." automatically as you type something?
Hey TMG, I was wondering what happens to the collider when you put a GO inside a SubScene without removing the collider. Does it work as hybrid ECS + GO?
The GameObject and collider would be converted into an ECS entity and ECS compatible collider. The regular Unity collider acts as an authoring component for the ECS collider in that case
Tks. I am waiting your video
Enjoy!!
If I'm starting to learn Unity from scratch, should I just wait for ECS and DOTS and forget about all the Unity Object Oriented courses and lessens out there? Really hope you can makes this an entire series to those of us who find DOD confusing.
If you're starting out, I'd highly recommend using GameObjects in the traditional Object-Oriented style. The OOP workflows aren't going anywhere anytime soon and as of now DOTS is really for those who are running into the upper limits of what traditional Unity can do. All the best with your game dev journey!
current rider has neat little helper than can generate component data from monobehaviour
Indeed it does!