Тёмный

2 Ways to use UI with Unity ECS 1.0 - Unity DOTS Tutorial 2023 

Turbo Makes Games
Подписаться 26 тыс.
Просмотров 19 тыс.
50% 1

📌 Project files from this video: www.tmg.dev/ecs-1-0-ui 📌
👨‍💻 Code/Scripts from this video: www.tmg.dev/ecs-1-0-ui-code 👨‍💻
💬 Come chat with other DOTS/ECS devs: tmg.dev/Discord 💬
📌 Watch my intro to DOTS 1.0 step-by-step tutorial video: • Unity ECS 1.0 Full Pro... 📌
🚧 Resources Mentioned 🚧
- Unity ECS 1.0 Tutorial Video: • Unity ECS 1.0 Full Pro...
- ISystem vs. SystemBase Video: • How to Use SYSTEMS in ...
- Unity ECS Learning Resources: github.com/Unity-Technologies...
💻 My Game Development Setup: tmg.dev/GameDevPC 💻
📸 My Camera Gear: tmg.dev/CameraGear 📸
🎮 Let me know what other topics you want to learn about 🎮
⌚ Time stamps for key topics ⌚
- 0:00 - UI in Unity ECS
- 1:15 - Sample Project Overview
- 2:15 - Event Based UI Theory
- 4:11 - Read Value UI Theory
- 5:55 - Combat System Overview
- 9:23 - Invoking UI Events
- 11:34 - World Space UI Setup
- 12:17 - Listening to UI Events
- 15:39 - Screen Space UI Setup
- 16:37 - Reading Entity Data from MonoBehaviour
- 21:12 - A Note on UI Events (Buttons)
🌐 Find Me Online! 🌐
📄 Blog: tmg.dev
👨‍💻 GitHub: github.com/JohnnyTurbo
🎮 Games: johnnyturbo.itch.io/
🦅 Twitter: / turbomakesgames
📺 Twitch: / turbomakesgames
🎵 Music by: Joakim Karud / joakimkarud
#️⃣ #UnityDOTS #UnityECS #MadeWithUnity

Опубликовано:

 

25 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 68   
@xinzhao64
@xinzhao64 Год назад
I am a full-time Unity development engineer.I like to watch your videos and learn from them.Although my English is not good, sometimes I use bullet screen translation. Thank you.
@TurboMakesGames
@TurboMakesGames Год назад
So glad to hear you've been learning lots from these videos! All the best 😊
@testitestmann8819
@testitestmann8819 Год назад
Thanks for your video. I'd love to see some (up to date) video about physics simulations in dots with collisions, raycast etc. Great work, keep it up.
@Armadous
@Armadous Год назад
+1 for the "new" input system integration. A quick unrelated side rant, I really think unity needs to take a hard line on what its next gen vision of the tool is. Making a modern unity project is about knowing what extra packages to install and what features to not use.
@TurboMakesGames
@TurboMakesGames Год назад
Awesome, glad you'd want to see some stuff on the input system! Hopefully I can bring some clarity as to what things you need in your Unity projects too 😊
@TenrousaAthena
@TenrousaAthena Год назад
I'm here just to learn about UI but your project has taught me more than that. Awesome! Thank you very much. Can't wait to watch your new Input system with ECS tutorial.
@TurboMakesGames
@TurboMakesGames Год назад
Awesome, so glad to hear it! Input system video should be up in a few weeks 😁
@Forjugadname
@Forjugadname Год назад
Great timing, I currently need to make a UI with these elements for my project. I was going to make some kind of UI system from scratch, but I realise I was over engineering the problem. Thanks for this.
@TurboMakesGames
@TurboMakesGames Год назад
Cool, hope it works out for you!!
@mattabrams3841
@mattabrams3841 Год назад
This was super helpful as always! I'm trying to work on a game like Risk of Rain 2, though a topdown 2d game, and I'm learning DOTS for the first time. It's actually going to be very functionally similar to your vampire survivors clone from the game jam, though with lots more enemies of course. I know you had mentioned more content on that later, so no rush of course, but what sort of content can we expect soon? I'd love to learn more about some of the content from this video expanded to jobs and fore higher entity and projectile counts, since things like single damage components might not suffice when an enemy gets blasted 20 times a frame. Similarly, I'm very excited to see how you implement the new Input system. I was gonna take a crack at it myself, but if you've got it in the works :). Thanks again for everything, you really produce high level, clear, concise, and helpful videos.
@TurboMakesGames
@TurboMakesGames 11 месяцев назад
Awesome, sounds like a cool idea for a game! Input system video is coming out this week so you won't need to wait long for that 😉 Dapper Dino did a video a while back on making a damage system in ECS where basically you use a Dynamic Buffer to keep track of all the damage added to an entity each frame, then you have a system run though and add up all the damage in the buffer. This would probably be a good thing to make an updated video on sometime though. Feel free to reference the GitHub repo from the VS clone if you want to see how this Damage Buffer is setup - github.com/JohnnyTurbo/LD53/tree/master
@bartekkarasek5660
@bartekkarasek5660 Год назад
Cool video! I like to connect both approaches by making a class in UI/View that wraps around a component and checks if it changed since the last time the view was updated or the previous tick in simulation (by calculating a hash code for example). And if it changed, it can invoke an event. If implemented well, you don't need to manually invoke events in simulation just because UI needs them and you can still have an event-based approach with less boilerplate code, though not without flaws. Photon Fusion uses it with "OnChanged" for their networked properties.
@TurboMakesGames
@TurboMakesGames Год назад
Oh nice that is a super interesting idea! Have you noticed any significant amount of overhead when keeping track of all the components and checking if they've changed?
@bartekkarasek5660
@bartekkarasek5660 Год назад
You instantly noticed :D This is one of the mentioned flaws. You need to be careful with this approach because it can result in a poor performance, especially if you calculate "GetHashCode()" for a huge array in UI in Update. In my project, most of the codebase can use it, but in some places I need to manually invoke an event as you explained in the video. The lack of consistency is a bit painful but it still saves a lot of time and code because I don't need to manually care in simulation about what events the UI or View will need. I'm also considering whether it is possible to check for differences on the ECS side - it should have a much better performance if you don't go into extreemes with the amount of entities and components.
@nooberiazi
@nooberiazi Год назад
tnx for covering dots
@bramblewoodhall4757
@bramblewoodhall4757 Год назад
I am currently porting my MonoBehaviour game from Unity 2021 to Unity 2022 to take advantage of DOTs, and this video is really useful for me to modify my existing code to provide Monobehavior/ECS interactions. The game is a multi-choice Adventure using INK book scripts - like an illustrated interactive book except that the illustrations are in the 3D. Most of the game doesn't need to be fast - my menu loop just waits for the player to make decisions, reads the Game Book then animates the 3D world accordingly and provides more book text and player choices. In short I want to use DOT's for animation and character controllers, but retain all the XML UI and MonoBehavior stuff that spends most of its time in a 100mS sleep, polling loop anyway. I am finding your Videos really useful, watching them repeatedly as I get my aged ObjectOriented brain used to thinking in the ECS way and start to understand the code as you describe it. I really appreciate that you updated the code for your Zombie Video to keep pace with the latest versions of DOTS. What I would like to see is efficient code templates for DOTS and the interaction between the new Unity MonoBehavior XML UI and DOTs - so I can still use my existing XML menu overlays, but take advantage of DOTS under the hood.
@TurboMakesGames
@TurboMakesGames Год назад
Good to know you'd be interested in something like that! All the best with upgrading your project - feel free to stop by our Discord to showcase your project if you want tmg.dev/Discord
@yudnai5577
@yudnai5577 Год назад
very cool video i didn't see any .schedule or .complete for the entities during the process does it effect threading and the memory allocation automatically when combining Mono with ECS?
@neilmarkcorre5524
@neilmarkcorre5524 Год назад
This is very timely as I am currently trying to optimize our management game. I am currently doing something similar to how you made the Read Value implementation - having a reference to an entity in the MonoBehaviour. Although, I did it such that an agent's entity is created when the agent's MB prefab is created. I understand that in your case, the player entity is a singleton entity, so it makes sense too, to do it the way you did. Curious, what are your thoughts on a Syncing system? I have something similar where a MB implements an interface that a syncing system is using so that if an IComponentData is changed, the data will be reflected in the MB's copy. I'm currently using an isChanged boolean in the IComponentData and a job collects all changed components, then a non-job method calls the MB's sync interface. I'm planning on using ECS 1.0's IEnableableComponent so that I don't have to go through a component that I know is not changed. In context, we are handling thousands of entities for pathfinding and AI. I made it a "restriction" to still keep a MB workflow to make debugging easier, and also so that designers and artists are still happy.
@TurboMakesGames
@TurboMakesGames Год назад
Right on, sounds like a cool project! Interesting solution you've came up with - though I'm not sure if the overhead of checking the isChanged boolean on each component is significantly more efficient than just updating everything every frame by default - but you'd have to do some performance testing to see what works better for you. Enableable components would be much more efficient, but there are other considerations you need to make when you are disabling components so your ECS systems still recognize that data on the entity. All the best!
@yuraYura-md2od
@yuraYura-md2od Год назад
Thanks, this is a good solution. I think this implementation can be applied to create Particle System prefabs.
@TurboMakesGames
@TurboMakesGames Год назад
Yes it can!
@tony355367
@tony355367 4 месяца назад
The online game made by my company crashed due to the UI. What you shared effectively solved the problem. Thank you for sharing.
@TurboMakesGames
@TurboMakesGames 4 месяца назад
Wow that is super to hear this worked so well for your team 😀
@xbbotz866
@xbbotz866 6 месяцев назад
Great Vid! Hi Turbo, I wish to know is it possible or is it good approach to put C# event in Aspect? Is it systembase the only place where C# event could be placed in ?
@TurboMakesGames
@TurboMakesGames 6 месяцев назад
I don't think that would work because all code in Aspects get generated into other code throughout the project. I suppose you might be able to store them in a managed component (class implementing IComponent data) but that might be a little weird. SystemBase is the only place I use them in ECS.
@muajin
@muajin Год назад
Do you by chance have a good tutorial on how to export android apks? I keep getting a debuginformation file instead of the apk when i build and buildmethod errors in unity. :(
@DraconicBovine
@DraconicBovine 10 месяцев назад
I foresee issues with the DamageToPlayer approach. In other games it would be feasible that the same character could receive damage twice in the same frame. And you can't add the same component type twice to an entity, so an error would be produced
@TurboMakesGames
@TurboMakesGames 10 месяцев назад
That is absolutely correct. I just made that super simple system for this video to showcase the UI, however in a real project I use a damage buffer where an entity can receive damage from many other entities in the same frame. Might want to do a video on this setup at some point
@raveir
@raveir Год назад
I would highly recommend a Animation overview with MonoBehaviours and DOTS.
@TurboMakesGames
@TurboMakesGames Год назад
It's on the list 😊
@Temasdin
@Temasdin 6 месяцев назад
Good video and the old one! But I would also like to share my experience: 1) At first, I've used the SharedStatic Messages approach to queue the received chat messages in the ECS system and then TryDequeue them in the Update() of the Mono UI element. This way is described in the official ECS chat sample, but if I remember correctly they use a slightly different type, which didn't work for me in the latest version of the ECS package, but the concept is the same. 2) Then I switched to a hybrid MVP\MVVM UI architecture with DI (Zenject) where the View cannot have any logic including the Update() method and everything is based on reactivity (models with reactive properties). So I just manually inject the model using the method's [Inject] attribute into the ECS system (given that we cannot use the ctor for it since it's used by the ECS container itself) and enable that system at the end of the method. And then change the model value to trigger the events Feel free to ask any questions. With love from Ukraine!
@Temasdin
@Temasdin 6 месяцев назад
I would also like to share my experience of working with Unity, C#, namely in complex issues such as UI and game architectures, and of course DOTS, as well as UGS or non-trivial topics such as baking animations into textures and how to combine and test it all. At this point I have an almost finished pet project based on this entire stack. However, I plan to do all this In Ukrainian, but I maintain and update the Readme in English. Of course I do not plan to make money from it)
@Temasdin
@Temasdin 6 месяцев назад
By the way, I was so happy and worried at the same time when you, Johnny, made a castle fight (warcraft 3 map) | nexus wars (starcraft map) like game because I had decided to make a game like that myself, but then a few days later you uploaded THE video... At least you didn't do multiplayer otherwise it would be really sad for me to repeat completely after you :D
@TurboMakesGames
@TurboMakesGames 6 месяцев назад
Hello and thanks for sharing your experiences! Sounds like you've got some really interesting projects in the works. Feel free to share them in the Discord when you're ready to show them off - tmg.dev/Discord Especially looking forward to the tug-of-war game as I think those are a ton of fun 😀
@Temasdin
@Temasdin 6 месяцев назад
@@TurboMakesGames sure!
@359Aides
@359Aides 11 месяцев назад
What are you thoughts on handling things like UI through managed components, similar to what you did in your earlier UI tutorial? Is it not practical anymore with Entities 1.0?
@TurboMakesGames
@TurboMakesGames 11 месяцев назад
Great question - managed components are a bit more difficult to work with now that we are forced into the subscene workflow, but they are still very important and useful. Will likely do a dedicated tutorial on them at some point.
@mehmetakyuz5290
@mehmetakyuz5290 Год назад
I've tried ECS Physics on mobile android device. Just 150 cubes falling dawn, and I get 20 fps. It's even worse than monobehaviour. Is this something expected? Or just happening on android? Would love to hear your thoughts or new video on it!
@GameDevNerd
@GameDevNerd Год назад
Note: An Action or Action is just a _delegate_ ... it's not an "event". An actual event is an event, and we make an action into an event by marking it with the `event` keyword. You may be tempted to simply make it a public "field style" event, but don't. Use full event accessors like the Microsoft C# documentation for best practices recommends, especially when code on multiple threads could potentially (or even _someday might_ end up) touching the event at the same time. That results in *undefined behavior* ... there is a misunderstanding people in the Unity community seem to have about this and the nature of events, and some people claimed Roslyn generates the same code and does all the work for you. As I have confirmed with ILDasm and inspecting the IL code generated for each, Roslyn does a _small part_ of the equation and generates a public accessor, but it doesn't implement the *lock* pattern or any "real" thread safety. So inside the add/remove accessors you need to wrap things in: lock( _objLock ) { // Handle things in here ... // You can log or set breakpoints too to debug registration/removal of subscriber pattern myPrivateEventField += _whatever_ ; }
@hominusprogramming
@hominusprogramming 10 месяцев назад
Hey, beautiful video! I have a question: you brought two examples where, in the end, it is always the ui that receives the data, but, what if I wanted the UI to send the data to a system? e.g. upon pressing a button an entity is spawned?
@TurboMakesGames
@TurboMakesGames 10 месяцев назад
This is something that would be good for a dedicated video tutorial, but one thing I was talking to Dani from Unity about on my recent livestream with him is to have UI elements spawn a companion entity at runtime, then the UI element can make things happen to that entity, which systems can run on. It is a few extra steps that need to be setup, but it works pretty well 👍
@hominusprogramming
@hominusprogramming 10 месяцев назад
@@TurboMakesGames Hi, thank you very much for your reply! It is indeed a good idea to test (which I will do as soon as I have some free time). While we're on the subject I'll bring to the "table" two possible solutions I've hypothesized (I don't have much time to use Unity recently, so I haven't tested them): 1 - Create a mono object with the Singleton pattern, the UI components communicate with the mono object via the preferred architecture (normally I go with the Channel/SO one) and the system (SystemBase) via the singleton (which can propagate the UnityAction to other SystemBase (I don't know if ISystem supports UnityAction) ). 2 - Still in the SystemBase system load the desired ScriptableObjects at runtime and use them from there (although I don't know how efficient this last option is)
@TurboMakesGames
@TurboMakesGames 10 месяцев назад
@@hominusprogramming both seem like solid approaches! Feel free to stop by our discord community if you'd like to chat with us about this! tmg.dev/Discord
@iainkey5102
@iainkey5102 Год назад
What's the best way of detecting collisions in ECS 1.0? I notice it's been a while since your last video on it, have things changed much with release?
@TurboMakesGames
@TurboMakesGames Год назад
It is still mostly the same where you use a ICollisionEventsJob, but this is definitely something I'd like to make some more videos on as there are many important topics to cover there
@iainkey5102
@iainkey5102 Год назад
@@TurboMakesGames sounds good, can’t wait for the update videos 👍
@LukeClemens
@LukeClemens Год назад
I have two issues with the event approach, and one minor issue with both. Event Approach Issue 1: You can only trip UI events from the main thread without burst. If there is some CPU intensive code that might every now and then trip an event, it would need to be converted to the main thread with burst disabled. There are event paradigms that can be sent from multiple threads, but they are more difficult to use than Unity events. Event Approach Issue 2: Fetching a system is generally not a good data orientated development practice. I think that's why Unity started adding a singleton to every system. In a "Data is King" approach, everything is tied together via the data and the various systems are ignored. So for example, if the UI was ported to a different game, that new game might have totally different systems transforming the data and the UI would still work because all it cares about is that the proper data is there - not a specific system. It contributes to modularity. That said - the whole point of this video is to hack around the fact that Unity UI is not DOTS enabled, so perhaps that could serve as an adequate excuse for an exception to this principle. Minor Issue With Both: It should be mentioned that DefaultGameObjectInjectionWorld could introduce problems in a game with more than one world. To be honest, I still use it in my monobehaviours because it's so convenient, but hopefully I'll find a better solution someday if I ever want to make the game multiplayer or use different worlds for game-saving or other things. Other Comments: 1) Unity events are around 20x slower than C# events (probably not a big deal for UI things). 2) Setting the target entity to the projectile is probably not a great idea unless you can guarantee that enemies won't move around - otherwise a projectile might hit enemy A and enemy B will die if the two switched positions as the projectile was traveling (not a problem for this simple example though). 3) By using a single damage component, there would be a problem if multiple players were blasting weapons at the same enemy - sometimes the bullets might hit on the same frame and only one bullet would get counted (again, not a problem since it's just a simple example). 4) It's worth mentioning that if it's anticipated that you might have thousands of events updating a counter or something at a rate faster than a couple of times per second, it would be more efficient to use the second approach with a timer - the human eye won't notice if something is updating faster than a few times per second so it would just be wasted CPU.
@sabiplaypuzzles7332
@sabiplaypuzzles7332 Год назад
Is ECS officially ready for production now or still in prerelease? We are finally almost in the middle of the year and last year (after so many years of development) it was said at the beginning of 2023 with Unity 2022 LTS. Well, you can't say they are lying at Unity as the 2022 LTS version hasn't been released yet. However, it should already be outside.
@TurboMakesGames
@TurboMakesGames Год назад
Actually, as recently as of yesterday, Unity released a full 1.0 release that is available through the Unity registry in the package manager - no experimental or prerelease tag!
@sabiplaypuzzles7332
@sabiplaypuzzles7332 Год назад
@@TurboMakesGames Glad to hear that. Then I can start studying your DOTS tutorials soon. I have one more question: Since DOTS has changed a lot in some aspects, which of your videos only focus on the stable current version of DOTS? Are you doing a full tutorial series for that?
@MalpTheCrow
@MalpTheCrow Год назад
hi! awesome video! thanks for your help to the developers community. I'm trying the read data solution, but i'm facing to on problem. You said "is a solution when you want to constantly read of changing data" but the system throws me an error, because i'm tryng to read data on entity wich is going to be use in a job (at least, it is what i understoob by reading the error in the unity docs) "NullReferenceException: Object reference not set to an instance of an object Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) " Any idea? :D
@TurboMakesGames
@TurboMakesGames Год назад
Not sure if this is the exact case, but you may be writing to that bit of data from one job (meaning the data is being modified in a worker thread) and reading from it on the main thread. Problem with that is that Unity can't guarantee if you are reading it before or after the data is modified. Solution would be to ensure that the scheduled job is completed before reading the UI data. One quick solution to this would be to put the UI system in the presentation system group as the job should be completed by then. Hope that helps!
@xxxxxx5237
@xxxxxx5237 Год назад
Hi Turbo. Do you try 1.0.8?
@TurboMakesGames
@TurboMakesGames Год назад
Yes I have! Seems to work well 👍
@justlama0
@justlama0 Год назад
Best way is to use mvvm pattern with ui tollkit where M -> ecs component data
@neilmarkcorre5524
@neilmarkcorre5524 Год назад
Interesting. I've only used the UI toolkit once but had to go back to the default UI as I'm not used to the toolkit's workflow. May I ask if there are performance overheads when using this implementation? I apologize for my lack of UI Toolkit knowledge.
@justlama0
@justlama0 Год назад
With event based approach we kill all dots performance benefits
@justlama0
@justlama0 Год назад
@@neilmarkcorre5524 ui toolkit much faster than ugui
@rthorat
@rthorat Год назад
Agree. UI Toolkit is the only way to go for someone using forward technology like DOTS. It performs better and is more modern and easier to maintain. Unlike some areas of DOTS that are completely missing, like animation control, UI Toolkit already exists and doesn't need any special DOTS support. It is tied to the rendering pipeline, such as HDRP and URP. And you should use UI Toolkit with both these rendering pipelines going forward. Unless you have some complicated use case that UI Toolkit does not handle well, and even then you should think about whether it's worth it investing in obsolete UI technology.
@watercat1248
@watercat1248 Год назад
Ecs the one thing that may be useful but never had the time or Courage to learn how it's work To be fer the are way more important stuff i needed to learn, like for example networking and inderfece Unlike ECS , inderfece and netcode it's essential for the game I'm working Im mean the ECS it may save a little bit performance or whatever But both inderfece and netcode the open i big potential and possibilities
@user-rb4bl6id9g
@user-rb4bl6id9g 5 месяцев назад
@path1024
@path1024 Год назад
You could just remove "actually" and "go ahead and" from all your sentences to save time on the video ;)
@TurboMakesGames
@TurboMakesGames Год назад
I think I'll actually go ahead and do that real quick 😁
@path1024
@path1024 Год назад
@@TurboMakesGames Im gud at advyc
@davidle360
@davidle360 Год назад
Thank you! Now I can go back to a project that I putted on standby because I didn't know how to deal with UI and ECS :). Especially, how to get the Entity from a Monobehaviour.
Далее
ОБНОВАА?? ЛУТАЕМ МЕГАЯЩИКИ
3:12:14
Просмотров 312 тыс.
MEGA BOXES ARE BACK!!!
08:53
Просмотров 32 млн
Thank you 3M❤️#thankyou #shorts
00:14
Просмотров 7 млн
Should You Use DOTS in 2024? (plus what is Unity ECS)
30:15
Unity Job System - A Practical Code Example
13:50
Просмотров 80 тыс.
ОБНОВАА?? ЛУТАЕМ МЕГАЯЩИКИ
3:12:14
Просмотров 312 тыс.