Тёмный

My Flow Field Pathfinding with Unity DOTS/ECS 

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

📌 Download the project files from this video: tmg.dev/DOTSFlowField 📌
📺 Learn how a flow field works: • How Flow Field Pathfin... 📺
💬 Join the conversation: tmg.dev/discord 💬
🎥 Flow Field Tutorial Unity MonoBehaviour: • Tutorial - Flow Field ...
🎥
👨‍💻 GitHub repo for this project: bit.ly/DOTSFlowFieldGit 👨‍💻
💻 My Game Development Setup: tmg.dev/GameDevRig 💻
👇 See below for time stamps 👇
- 0:00 - Introduction and Project Demonstration
- 2:45 - Unity Project Setup
- 4:32 - Script Organization
- 5:13 - Initialize Flow Field System
- 6:59 - Initialize Flow Field Grid System
- 13:20 - Calculate Flow Field System
- 18:27 - Entity Movement System
- 21:00 - Final Demonstration and Thoughts
Links:
Blog: tmg.dev
Twitch: / turbomakesgames
Twitter: / turbomakesgames
Game Studio: homecookedgames.com
GitHub: github.com/JohnnyTurbo
Music by: Joakim Karud / joakimkarud
📸 My Camera Gear: tmg.dev/CameraGear 📸
🎮 Let me know what other topics you want to learn about 🎮
#UnityDOTS #Unity3D #MadeWithUnity
Please 'Like' this video and share it with anyone who is interested in video game development.
Subscribe to the channel for much more independent video game developer related content including tutorials, design breakdowns, industry events, VLOGs, and much more fun stuff!

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

 

16 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 41   
@TurboMakesGames
@TurboMakesGames 3 года назад
Let me know what you all think about my implementation of the flow field using Unity's Entity Component System. Let me know if there are any glaring things to fix in my code before I start running the performance tests. Note that I will be running the performance tests in standalone builds of the game - which will most certainly have better performance than running in the editor. Anyways thanks for stopping by 😀
@eizenhorn91
@eizenhorn91 3 года назад
No offence, but really bad example. Using physics for costs generation and rasterization obstacles to flatten grid - terrible idea. Get rotated rect projection and rasterize object to flatten map will be much more efficient. Many unnecessary copying, managed types, FlowField and cells as managed types unnecessary etc. Better is implement pretty simple, and much more efficient own native container and couple of unsafe types and operate on pointers. It was about the implementation of general things. Now about algorithm implementation - naive approach. This approach not scales at all, and wouldn't work efficiently on even 500x500 map with 2k of agents (map scale extremely matter in flow field pathfinding approaches) with multiple destination points (current implementation don't even support multiple fields). Caching and field reusability does not exist at all here. This should be implemented with regions separation and Hierarchical A* on the top level of regions with regions merging and per region flow fields generation, in that case, most part of agents will reuse already generated fields, and longer you'll play - lighter pathfinding become as cache populates (up to some reasonable size) and units don't even generate new fields and just reuse them even in the future path requests. Moreover, regions approach handle dynamic obstacles change much better as it requires only rebuild a small piece of the map (a couple of regions). I recommend reading these two papers: www.gameaipro.com/GameAIPro/GameAIPro_Chapter23_Crowd_Pathfinding_and_Steering_Using_Flow_Field_Tiles.pdf grail.cs.washington.edu/projects/crowd-flows/ Again - no offence, you asked, I'm answered :D P.S. As some foundation, to make it clear that I know what I'm talking about, you can watch this my pinned thread on the Unity forum (in the area of 2 and 3 pages): forum.unity.com/threads/unity-ecs-and-job-system-in-production.561229/page-2 Or just look at the game we are making to understand that we have enough experience in this to make recommendations: store.steampowered.com/app/1272320/Diplomacy_is_Not_an_Option/
@TurboMakesGames
@TurboMakesGames 3 года назад
@@eizenhorn91 No offense taken - this is some extremely valuable feedback, I really appreciate you for taking the time to write such a detailed response. The cost field generation was meant to only be a quick (to implement) and dirty way of going about things, but I do appreciate the suggestions to improve performance. This project has been my first implementation of flow field pathfinding so I was definitely focused on simplicity. One of the things that really appealed to me during my research on the flow field algorithms, was how you could break it up into sections and combine it with other algorithms like A* like you mentioned. Super smart to cache those sections to reduce generation time over the life of the game. I've seen a bunch of your posts on the forums and they've been very helpful as I try and piece together Unity's ECS and the best way to go about things - so thanks for the tips here and on the forums 😀 Again, really appreciate the time you took to write such a detailed response with reference material included. Also your game looks really freaking cool and I wish your team the best as you head into early access and towards release. Looking forward to seeing more of it ☺️
@NukeCloudstalker
@NukeCloudstalker 3 года назад
​@@eizenhorn91 Thanks, I got value out of reading your feedback too. It's great to see you and TMG handle this so well, info-sharing in the industry is essential to increase standards and help people learn the necessities after all. Do you know any good resources on using pointers and unsafe types? My only formal experience with programming is C#/Python/JS, and we never covered pointers at university, sadly, so anything that offers a holistic view of pointer-use I'd appreciate a lot, as all I can find when I start to look into it, is specifics, much too often separated from the whole..
@nyscersul42
@nyscersul42 Год назад
When working with something like dots/ecs, seems much better to discard any attempts to use physics, and instead cover the management of data yourself, so you can squeeze every drop of work out of them.
@varnonzero
@varnonzero 3 года назад
I enjoyed these flow field videos. My suggestion at this point would probably be to just use monobehavior + jobs. The potential performance boost with jobs and the burst compiler is pretty solid, and coding style seems to be stable. So far jobs has also been faster than compute shaders for me. For many things, you can also trash the game object and draw objects manually with Graphics.DrawMesh or a similar instruction. Then, ECS should only be benefiting in data alignment (I think). ECS just seems to be more complicated than it is worth right now, and it still seems to be changing quite a bit. Its there if you just really want an adventure, but I wouldn't use it in practice yet. I'm definitely looking forward to getting into ECS when it is more developed.
@TurboMakesGames
@TurboMakesGames 3 года назад
Fair points. I do think the job system is really powerful and it's really nice that you can implement it with existing code fairly easily. The more I dig into ECS, the more I see just how complex it is. Yes you can get excellent performance but you are also locked in to a very specific way of doing things with lots of boilerplate code. Will be interesting to see how it evolves to become more user friendly and widely used.
@varnonzero
@varnonzero 3 года назад
@@TurboMakesGames I just finished converting my bois Monobehavior + Jobs + Graphics.DrawMeshInstanced code to ECS yesterday, and I'm actually getting very similar performance, with ECS being a tiny bit less performance. I might find a way to optimize the ECS version a little more. Either way, it is still a LOT of boids. I'm thinking ECS might not really be that much better for a single system, but the more systems and complex the game or simulation, I think the more ECS will shine. That is a little harder to test though. I do admit that once you have the ECS bugs worked out and have sifted through the documentation, it is rather satisfying to get it all working. Even though I didn't get the massive boost I wanted, now that I've given it a proper comparison I think I'm even more excited to see what ECS becomes.
@crefelder1
@crefelder1 6 месяцев назад
Many thanks for this. I would like to see this as an only code version without the stuff using unity components. I can create a BFS grid and also a grid with the weights. Also collision circle-circle and circle to concave polygon. Only code. But I am stuck at combining them with entities. Some entities are pushed inside the walls by the mass of the others. Or some of them are not getting an direction from grid because they are over grid cells without direction depending on walls.
@Ne0mega
@Ne0mega 3 года назад
Suggestion for series: ECS fog of War and line of sight. Essentially ECS point lights. I have been working on a system for a while, decided it would probably be best done in ECS. Making an RTS, I need all sight to be accessible by the AI often, and I also need to be able to save the fog of war to a map for save games. This has proven to be quite challenging, as most asset store packages seem to be mostly visual, and none of them work with SRP because of current post processing issues. I know ECS structure would be better, where an AI controller has all units report a line of sight at once, and then update its own map. Also, almost ALL DOTS and ECS tutorials for anything (I have only found one channel exception) are done on FLAT planes with Objects as obstacles. I think most 3d devs are using rough 3D terrain, which greatly complicates things.
@TurboMakesGames
@TurboMakesGames 3 года назад
I like the idea, I'll definitely note that one 😀
@mattseaton5832
@mattseaton5832 3 года назад
Is there any reason to make the cells entities? I mean they aren't actors in the scene, just passive data structures. What is the advantage vs just storing a persistent NativeArray?
@codytownsend3259
@codytownsend3259 11 месяцев назад
Simply to use it in the DoTs system I suppose
@jackadam98
@jackadam98 3 года назад
Im still trying to wrap my head around how ECS works. Rather than being a gameobject, ECS turns what would be individual gameobjects into entities right? My question is, can these entities in ECS store their own private data, such as a unique movement speed and maybe a value for distance traveled, or does that defeat the purpose of ECS? For ECS to work, do entities need to be exactly identical? Also, while in game, can you convert a gameobject into an ECS entity to maximize performance, then when unique functions need to occur, turn that entity back into a gameobject for a complex task? What actually is the difference between a gameobject and and ECS entity? From what i understand, each gameobject is standalone whereas an entity is and identical reference to one original entity. This confuses me because I would assume this is quite limiting, yet I see people use it to perform quite complex tasks, such as your video which im having trouble understanding. Is each cell in a grid in this video an entity with unique values? Does these mean the answer to my question about unique movement speed is yes? Lastly, where are you getting your info about ECS because im having trouble finding resources to answer my kinda specific questions? Thank you for your help, Jack
@Forjugadname
@Forjugadname 3 года назад
ECS is just all data. The entity is just a reference, you can have an empty entity with no component data, but I'm not sure if that would be useful for anything. You store component data on that entity. You can have all kinds of unique data on individual components on that entity. This is a good reference www.dataorienteddesign.com/dodmain/
@TurboMakesGames
@TurboMakesGames 3 года назад
Check out this video I made that introduces the concepts of ECS in Unity - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HVzSTEIAXi8.html Like Calabi said, the entities don't contain any data, they just point to data components in memory - each data component can have its own unique values. Entities with the same components are grouped together in memory for quick access in things called archetypes, but you can have pretty much as many archetypes as you want (until you run out of memory) You can convert GameObjects to entities but you can't convert entities to GameObjects. If you still want some behavior that entities can't do yet (there are still a bunch of things that don't have full support yet) you can inject a GameObject into that conversion, then sync the transform of it with the entity each frame. Again yes, entities can have references to data components with unique values. Entities with the same component references are grouped in memory for quick access, but you can still easily add/remove components for dynamic behavior at runtime. There is also a concept of SharedComponentData where many entities reference the same data component with the same values - can improve efficiency and memory usage if many entities need to reference the same values. The ECS info is quite sparse but I look at the official Unity documentation a lot, the Unity forums, and some other blogs and RU-vid videos. Hope that helps make more sense of it all!
@NukeCloudstalker
@NukeCloudstalker 3 года назад
I know I'm pointing outside of Turbo Makes Games channel here, but I think if you want intro to these concepts / a good mental model of it, Brian Will has some great videos on this. Probably has a lot of overlap with things discussed on this channel, but it's more collected there and was a great primer for me. :)
@Forjugadname
@Forjugadname 3 года назад
What packages are you using? I'm getting lots of errors like "Library\PackageCache\com.unity.jobs@0.5.0-preview.14\Unity.Jobs\IJobParallelForFilter.cs(134,30): error CS0117: 'ScheduleMode' does not contain a definition for 'Parallel". I've got Entities the latest versions and all its dependencies plus the hybridrender. I'm not sure what is going wrong here.
@TurboMakesGames
@TurboMakesGames 3 года назад
Hybrid Renderer - 0.8.0 Entities - 0.14.0 Burst - 1.3.2 Jobs - 0.5.0 Physics - 0.8.0 Those are the main ones I'm using in this project. You may just need to clear the errors or restart Unity
@Forjugadname
@Forjugadname 3 года назад
@@TurboMakesGames Thanks, it seems like I need Unity 2020.1 instead of 2020.2 also Unity.Physics version 0.4 instead of 0.41 to get it to compile without any errors. But then when I run it, I'm getting errors like "The managed class type `TMG.ECSFlowField.EntityMovementSystem` is not supported. Loading from a non-readonly static field `TMG.ECSFlowField.EntityMovementSystem.instance` is not supported" also lots of burst warnings.
@Forjugadname
@Forjugadname 3 года назад
I changed to Burst 1.3.2 and I'm still getting errors like " The `try` construction is not supported" I'm missing some version.
@Micz84
@Micz84 3 года назад
If you are using Unity ECS physics then probably the reason for this performance drop is the calculation of collisions.
@TurboMakesGames
@TurboMakesGames 3 года назад
I am using Unity ECS Physics - definitely seems that the slow down is caused when all the entities are close and lots of collisions are happening
@bilal12e
@bilal12e 3 года назад
please make video on Navmesh
@TurboMakesGames
@TurboMakesGames 3 года назад
Unfortunately, Navmesh is not compatible with ECS right now - I will definitely make a video once this support is added 😊
@mattseaton5832
@mattseaton5832 3 года назад
@@TurboMakesGames It is. There's a thread on the unity forums.
@abulak3477
@abulak3477 Год назад
23:09 where?
@TurboMakesGames
@TurboMakesGames Год назад
Didn't end up doing one as I didn't really like how the ECS implementation of this turned out... Though now that I have much more experience with DOTS and the API has changed so much, this is certainly something I'd like to revisit
@testnameone806
@testnameone806 3 года назад
Seeing this error "Assets/Scripts/ECS/Systems/InitializeFlowFieldGridSystem.cs(26,8): error CS0103: The name 'GetBuffer' does not exist in the current context: with the code, wonder what versions of unity / ECS packages your using.
@TurboMakesGames
@TurboMakesGames 3 года назад
I'm using the latest - version 0.14 preview 18. Looks like the GetBuffer function was added in entities version 0.12
@iOddWorId
@iOddWorId 3 года назад
Not entirely sure what's causing your performance hit, but maybe you could try implementing a flocking algorithm so they don't stack like that, obviously depends on what you're trying to achieve in your game. Great vid bud, looks like a lot of hard work. You really gotta work on commenting your code though!
@TurboMakesGames
@TurboMakesGames 3 года назад
Great point, I do think some sort of flocking algorithm would help so all the entities aren't essentially fighting over the same position on the map. Lately I've been trying to work on writing cleaner "self-documenting" code that doesn't need to rely on comments to explain what it is doing - though I could see how it would be helpful for the showcase/tutorial videos 😋
@testnameone806
@testnameone806 3 года назад
@@TurboMakesGames My first thought is collision physics becoming an issue. Since you have already sub divided the space into cells, I would look at using some 'bucket' system that limits the number of units per cell, and only tests for collision among units and objects within the same bucket, greatly reducing the collision tests. I think thats what the Unity 2017 ECS demo did.(I would profile the code first though)
@TurboMakesGames
@TurboMakesGames 3 года назад
Yeah definitely feels like the physics interactions are slowing things down, haven't had a chance to profile it to be sure but that is likely the first place I will be looking. Thanks for the suggestion though 😊
@iOddWorId
@iOddWorId 3 года назад
@@TurboMakesGames I just finished writing my own implementation of a Monobehaviour/non-ecs version of the flowfield (with the help of your other tutorial, thank you so much btw) and i thought of a possible solution that wouldn't require writing a flocking algorithm to help alleviate that performance hit. What if you just made it so when an entity reaches the destination, it sets a boolean value "arrived" to true, and then any entity that collides with an entity that already has that boolean set to true, then it also stops, and sets it's boolean flag to true? Could even add a short 0.2 second timer before it sets the flag, just to ensure they really bunch up, but not excessively. Might cause performance hit while traversing the world, but you could just ignore that check if the entity is too far away from it's destination.
@TurboMakesGames
@TurboMakesGames 3 года назад
I like that idea a lot. I've already got the destination reached value in one of my data components so it'd be as simple as setting that to true on collision with an entity where it is also set to true. I'm a fan of the simple solutions 😊 I'll definitely experiment with that - although this wouldn't help with any performance issues experienced while traveling to the destination. I guess I'll just have to play with it and see how it runs. Thanks!! (glad you made your own flow field BTW)
@abgames2646
@abgames2646 3 года назад
Make rts game tutorial in dots
@TurboMakesGames
@TurboMakesGames 3 года назад
Thanks for the suggestion, I think that would make for a good comprehensive DOTS/ECS tutorial!
@shenshaw5345
@shenshaw5345 2 года назад
damn this stuff is complex
@TurboMakesGames
@TurboMakesGames 2 года назад
You can get waaay more complex than this if you need the extra features 😋
Далее
Should You Use DOTS in 2024? (plus what is Unity ECS)
30:15
impossible to understand how😨❓
00:14
Просмотров 2,5 млн
Спецэффекты в Симс 4
00:36
Просмотров 247 тыс.
How do vector field Pathfinding algorithm work ?
7:12
EA Won't Let Me Play This Game - So I Hacked It
8:49
Просмотров 296 тыс.
Options for Entity interaction - Unite Copenhagen
43:12
Coding Adventure: Boids
8:35
Просмотров 1,5 млн
I Optimised My Game Engine Up To 12000 FPS
11:58
Просмотров 588 тыс.
Making MULTIPLAYER Games has never been EASIER!
12:49