Game Objects with Unity DOTS Pathfinding! (ECS mixed with MonoBehaviour)

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024

ความคิดเห็น •

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +10

    Here's one way to mix Game Objects with super fast DOTS code!
    How would you mix them in your games?
    These complex DOTS videos take a long time to make so if you find them helpful consider supporting on Patreon or picking up the Game Bundle
    📍 www.patreon.com/unitycodemonkey 📦 unitycodemonkey.com/gamebundle.php

    • @b1ngb0ng2
      @b1ngb0ng2 4 ปีที่แล้ว

      please do 2d post prossecing

    • @MasterofFire-sc3yn
      @MasterofFire-sc3yn 4 ปีที่แล้ว

      Hi Code Monkey,
      How do you use separate sprites in a sprite sheet and still do the animation (in the files of the marine sprites)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      @@MasterofFire-sc3yn Check out this video where I cover how my animation system works th-cam.com/video/11c9rWRotJ8/w-d-xo.html

  • @themadmadsen
    @themadmadsen 4 ปีที่แล้ว +31

    You are freaking brilliant, this was EXACTLY what I was wanting to do with our current game and here you are swooping in and saving me hours and hours of research time and troubleshooting. New Patreon supporter incoming!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Awesome! Glad you found it helpful!

  • @blobfish5713
    @blobfish5713 4 ปีที่แล้ว +5

    I recently found your content and it helped me improve a lot! Thanks a lot of sharing and making us videos for free, we highly apperciate that

  • @varnonzero
    @varnonzero 4 ปีที่แล้ว +1

    Excellent video. This should have way more likes. Mixing ECS with monobehavior seems incredibly useful.

  • @jorouss33
    @jorouss33 4 ปีที่แล้ว +4

    Yep, there we go

  • @RiderontheStorm1992
    @RiderontheStorm1992 2 ปีที่แล้ว

    This is the exact topic I needed. Thanks Code Monkey!

  • @tfmate-ij5em
    @tfmate-ij5em ปีที่แล้ว

    asked that already but still, any way to avoid graph initialization for every unit (every job)?
    Like if its 200x200 +, stored in OOP way, converting every time to NativeArray graph
    May be use some kind of FindPaths job with n nativelist fields for paths and call it with n sized packs?
    So at it will at least create one graph for n path calculations

  • @JaredBrandjes
    @JaredBrandjes 4 ปีที่แล้ว +1

    Great set of tutorials! Very informative. Thanks! I've been following along with a few tweaks here and there to work with my game.
    I'm seeing spikes in the profiler when calculating particularly lengthy paths and I was wondering if cutting the paths into sets with a max node count would allow a single path to be calculated more efficiently. Basically in 2 parts:
    1. Calculate the 'path intention' by limiting the initial path calculation to, say, 20 nodes. Calculated in a single frame.
    2. Use the end position of the 'path intention' as the start to then calculate the rest of the path over multiple frames if needed. The rest of the path should be able to calculate without holding up a frame and before the unit gets to node 20.
    I'm interested to hear your thoughts and how you'd do it. Also, I'm quite unsure how to get a job to complete over multiple frames in this context.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      Yup that is exactly how its done for massive maps, you split it into multiple maps and stitch the final path together. It's a pretty complex topic but that is definitely the way to go. I remember reading a bunch of interesting articles on how they solved that problem for Factorio which has massive maps.
      I don't think there's a pre-built way of running a job over multiple frames, you need to split it and handle it yourself.

    • @JaredBrandjes
      @JaredBrandjes 4 ปีที่แล้ว

      Code Monkey thanks man. I guess I’ll attempt it. Need to do more research on ECS and particularly dynamic buffers as I think that’s probably the way to go with glueing the parts together. It does take a bit longer to wrap my head around these concepts, coming from an OOP background.

  • @caxopog
    @caxopog 4 ปีที่แล้ว +3

    And what is better to chose for making game from scratch - full DOTS or this "combined" method?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +3

      DOTS is still very much in development so the combined approach is best right now. If you go full DOTS you have to make your own systems like Animations, UI, etc

  • @elyr1um
    @elyr1um ปีที่แล้ว

    How do I make it so that the job can also check if the node is overlappoing with a tilemap collider? I've tried OverlapPoint but it only works in the main thread, and I don't know how I should access it outside of the 2 for loops

  • @taylors1545
    @taylors1545 4 ปีที่แล้ว +1

    Your pathfinding system builds a new grid for each request.
    It would be nice to see how to batch requests so the grid is built once.
    Or, use a second system for updating a persistent grid.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      Yes a batching system is definitely something that Id like to cover, its the way to go in order to use it in a proper game

  • @neozoid7009
    @neozoid7009 2 ปีที่แล้ว

    Hello CM, I am still a beginner in unity I have a Question to ask which is bothering me , Is this type of mix DOTS and GameObjects a Best way to Apply in a Project or Should one go full on DOTS or GameObejct?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      DOTS is still in development so there are no "best" practices yet, this is one approach which may or may not end up being best in the long run

  • @mythik9636
    @mythik9636 4 ปีที่แล้ว +1

    I love how clean your code is and is so easy to read. What ICE do you use?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      IDE? Im using Visual Studio Community

    • @mythik9636
      @mythik9636 4 ปีที่แล้ว

      ​@@CodeMonkeyUnity ok

  • @Liqvidniy
    @Liqvidniy 4 ปีที่แล้ว +1

    Hello, thank you for pouring light on dots.
    1. Is there a way to use dots collisions with game objects collisions. If not, for performant physics one should choose dots physics on all game objects(via entity companion)?
    2. How to handle events in dots? Say entity has an event OnDamageTaken and some other components or entities should subscribe to it and trigger code at the moment than damage was taken? Could it also be done with multithreaded jobs?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      The physics worlds cant mix, so either go full dots physics or full gameobject physics
      Events are tricky, best approach is probably to just add a.component when the event happens and then handle it. Still need to research the best way if handling events

  • @Truth-Voyager
    @Truth-Voyager 4 ปีที่แล้ว

    When I try to make the grid bigger than 125X125 it wraps on itself. It basically reaches the specified number of rows, I want it to be 250X250, but when it reaches 125 columns the grid wraps back and puts the next column over top of the first column and the next column over the second column and so on. Any idea why this is happening and how to fix it?
    Update: The wrapping seems to happen any time the number of nodes is greater than 16385.

  • @rafalwilczek2301
    @rafalwilczek2301 2 ปีที่แล้ว

    First Thanks u So Much for Sharing this with us.
    Second u got new patron :)
    Thinking, how to set Grid is already Occupied when unit stay now here, every step checking if path is still valid & next grid is not occupied by somebody. Thinking how to implement, "Collisions Like", 2 units can't stay/walk on same grid in same time :) somebody must be first

  • @SkrekkLich
    @SkrekkLich 4 ปีที่แล้ว

    I recently discovered your channel. I really like it so far. Especially since it's not the typical "beginner" stuff. One question though: What is your intention of the sections where you speed up your coding (especially the part where you add more units and don't explain what you did)? Just curious since parts like this could be left out if we don't get to see what exactly you did there (At least for me it doesn't matter what you did there since for me it's more about the concept and techniques etc Blabla :D)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      My intention with speeding up is simply so the videos don't end up super long. People don't watch 30+ or even 20+ minute videos so in order for the TH-cam algorithm to not bury my videos I speed up the parts where all I do is write code.
      I do normally stop and explain what I did unless its something super basic or something that isn't relevant to the video topic. At 14:10 I speed up making more units which is simply duplicating them and writing the Pathfinding roaming code that I wrote in the previous video.

    • @SkrekkLich
      @SkrekkLich 4 ปีที่แล้ว

      @@CodeMonkeyUnity Thank you for your reply. I like the speeding up as is. But the part with the units could have been skipped completely imo, since you did not explain anything special afterwards, thats my MINOR critic. As of now I think you are delivering the most useful and polished Unity videos with interesting topics and a good pace. Good to follow along and if I want to try it myself, I can pause the video, since you tend to keep the relevant Code blocks visible :) Keep up the awesome work!

  • @Truth-Voyager
    @Truth-Voyager 4 ปีที่แล้ว

    When I try to build a game using this to my iPhone I get null entities errors. I don’t get these errors in the editor. Any idea why this is happening?

  • @MGConstantin
    @MGConstantin 4 ปีที่แล้ว

    Nice video. Keep up the good work. Opinion : older intro was better :D

  • @johnanthony44
    @johnanthony44 4 ปีที่แล้ว +1

    What are the Frames/Sec stats for each of the methods? Pure DOTS vs the hybrid approach.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Rendering is a lot faster in pure DOTS. At most I can get maybe 3,000 of these animated units whereas with DOTS I can get it up to 100,000

  • @christopherk4504
    @christopherk4504 4 ปีที่แล้ว

    Can I use Dots in a webgl build? I read that Threading is not supported but how is it with Dots?
    Do you know anything

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      I haven't been following the WebGL features for a while now but I believe the Job System works fine and the only issue right now is with the Burst Compiler.
      But not sure so make your build for WebGL and test it out.

  • @__Rizzler__
    @__Rizzler__ ปีที่แล้ว

    how did you learn all ecs functions and stufff? i find this a bit hard for me to understand

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      By reading the documentation, it has tons of info docs.unity3d.com/Packages/com.unity.entities@1.0/manual/index.html

    • @__Rizzler__
      @__Rizzler__ ปีที่แล้ว

      @@CodeMonkeyUnity thanks code monkey

  • @ElementalCode
    @ElementalCode 4 ปีที่แล้ว

    I have noticed that even when you use gameobjects without dots you never use the "Sprite renderer" but you go for a mesh renderer with a 2d image (a quad?)
    Why is that?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Just because that's how my animation system works, it works by dynamically modifying a mesh in run time. Everything would work the same with a animation system that is based on the SpriteRenderer

  • @florinpricopie9112
    @florinpricopie9112 4 ปีที่แล้ว

    I'm trying to figure out , how to acces wheel collider from ECS , any solution ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      I don't think DOTS Physics has such a specific collider yet, you can write your own Wheel logic using the Cylinder.

  • @puppetlord1908
    @puppetlord1908 4 ปีที่แล้ว

    I found that Convert isn't called instantly when i instantiate the prefab this way.
    I instantiate the gameobject prefab
    It's entity is spawned the next frame.
    How can make the "Convert" work instantly?

    • @puppetlord1908
      @puppetlord1908 4 ปีที่แล้ว

      I think a system calls the Convert() from outside.
      If so what system is that? I need a name.
      So i can call it's Update()

    • @puppetlord1908
      @puppetlord1908 4 ปีที่แล้ว

      That was just not necessary and optimal, i ended up instantiating my "companion entities" trough EntityManager

  • @DanyloSyrotynskyy
    @DanyloSyrotynskyy 4 ปีที่แล้ว +1

    Do You have idea how to implement collision detection?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Sure, DOTS Physics is already pretty advanced th-cam.com/video/B3SFWm9gkL8/w-d-xo.html

    • @DanyloSyrotynskyy
      @DanyloSyrotynskyy 4 ปีที่แล้ว

      i mean to make useful for 10000 units)
      as navmesh obstacle avoidance works
      not sure if physics is enough performant (as it is more accurate)

  • @marymarin3506
    @marymarin3506 4 ปีที่แล้ว

    Привет, смотрю твои видео, очень нравятся, но скажи пожалуйста почему когда я скачиваю материалы из видео, у меня либо миллион ошибок либо просто всё фиолетовое
    Heeelp please

  • @puppetlord1908
    @puppetlord1908 4 ปีที่แล้ว

    How can one manually update the physics systems like BuildPhysicsWorld, StepPhysicsWorld, and ExportPhysicsWorld? This is needed for some multiplayer architectures (including mine :))

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Hmm you can do it with custom system but not sure with the built-in ones. Maybe you can manually remove it from the world and add it again.

    • @puppetlord1908
      @puppetlord1908 4 ปีที่แล้ว

      @@CodeMonkeyUnity Here is what i did :)
      This is in monobehaviour
      sysGroup = world.GetExistingSystem();
      public void Simulate(int frames)
      {
      sysGroup.Enabled = true;
      for (int i = 0; i < frames; i++)
      {
      sysGroup.Update();
      }
      sysGroup.Enabled = false;
      }
      What i did with .Enabled was necessary

  • @danieldahl4585
    @danieldahl4585 4 ปีที่แล้ว

    Would it be possible to make DOTS do the rendering of a gameobject?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Sure, DOTS is super useful for rendering tons of objects th-cam.com/video/t1f8ZreCuuQ/w-d-xo.html

  • @Truth-Voyager
    @Truth-Voyager 4 ปีที่แล้ว

    What values do I need to change to increase the size of the grid? Presently the cell sizes are 1x1 I need to up that to 100x100 and still have all of the path finding work. I found where to increase the scale size but the unit continues to move around like the cells are still 1x1. Any ideas?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      The pathfinding returns int2's of the positions to follow, you can then transform those values to whatever you want like multiply them all by 100 to match your world units

    • @Truth-Voyager
      @Truth-Voyager 4 ปีที่แล้ว

      @@CodeMonkeyUnity Which lines are you referring to in particular? This one?
      path.Add(new int2(endNode.x*150, endNode.y*150));

    • @Truth-Voyager
      @Truth-Voyager 4 ปีที่แล้ว

      Never mind, I figured it out. Thank you for the awesome video!

  • @tfmate-ij5em
    @tfmate-ij5em ปีที่แล้ว

    Any way to update it to 1.0?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      The syntax has changed quite a bit so there's no easy way to upgrade, but all the core Data Oriented concepts are the same

  • @badrballish9328
    @badrballish9328 3 ปีที่แล้ว

    👍👍👍👍👍👍👍

  • @guigamer0077
    @guigamer0077 4 ปีที่แล้ว

    pls make a enemy system pls

  • @aggressivemastery
    @aggressivemastery 4 ปีที่แล้ว +1

    :O

  • @sunnyboy7358
    @sunnyboy7358 2 ปีที่แล้ว +1

    Unity ECS 0.5 Update removed JobComponentSystem. Your code is broken and dont work. Please have a look at it and fix it. Not very good tuturial material

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Videos on TH-cam cannot be updated, look in the changelogs to see what the JobComponentSystem changed to

  • @lidiadup1648
    @lidiadup1648 4 ปีที่แล้ว

    Hello

  • @traptown5611
    @traptown5611 4 ปีที่แล้ว

    Code Monkey

  • @ArnCiS96
    @ArnCiS96 4 ปีที่แล้ว

    Hmm, it kinda nonsense why in hell you do copy&pasting instead of adding required components and implemented systems will do rest? Kinda misleading workflow :/

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      What do you mean? All the code that I copy pasted was fully made in one of the previous videos so I didn't want to waste time repeating myself over again