Insanely FAST Spatial Hashing in Unity with Jobs & Burst

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

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

  • @git-amend
    @git-amend  หลายเดือนก่อน +10

    Happy Sunday! 😊 Thanks for watching, and if you found the spatial hashing concept helpful, don’t forget to LIKE and subscribe and drop your questions below!

  • @hop3studio511
    @hop3studio511 หลายเดือนก่อน +14

    Your tutorial release schedule is on fire 🔥 bro, and not just fast, but advanced.... Glad we have you as unity tutorial channel, keep it up

    • @git-amend
      @git-amend  หลายเดือนก่อน

      I appreciate that!

  • @selmansavas586
    @selmansavas586 หลายเดือนก่อน +7

    As always, right when i need something like this ❤ There is no other like your content, the topics, the quality, the soothing voice, its just ❤🤌
    Thank you for the awesome content 🎉🎉

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Thanks for watching and the kind words!

  • @silchasruin4487
    @silchasruin4487 หลายเดือนก่อน +3

    Love the video! I love to actually see these optimization techniques, tools and experiments along with the stress tests behind them. Especially when optimization is not a huge focus on game dev and tutorial channels, since that can be the achilles heel of many noob game devs. I remember starting out, following a tutorial thinking this will be the foundation for my procedural open world game aaaand you realise you can't do anything else with the project. Have a good one, looking forward to the next one!

    • @git-amend
      @git-amend  หลายเดือนก่อน +2

      Thank you! Glad you enjoyed it!

  • @Anvelir
    @Anvelir หลายเดือนก่อน +3

    OMG. This is exactly what I needed for my Voxel systems.

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Awesome! Glad to hear that!

    • @Anvelir
      @Anvelir หลายเดือนก่อน +1

      ​@@git-amend I tried to mess up with OctTrees, not only from your last video. But I noticed they have problem - extended, long objects are creating very huge, inperformant tree.
      And also it is hard to control, add and remove objects - you have to debug it in the recursion, trying to catch the error or spontaneous nulls...
      This algorithmic data structure you brought saved my nerves very much :)

  • @starplatinum3305
    @starplatinum3305 หลายเดือนก่อน +1

    I just love optimizations bro
    Who let him cook 🗣️🔥🔥🔥

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Thanks!

  • @ankitwarkade6920
    @ankitwarkade6920 หลายเดือนก่อน

    I was eagerly waiting for this☺

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Awesome, hope it helps you out!

  • @rambertoeco8930
    @rambertoeco8930 หลายเดือนก่อน

    Cool stuff and all explained so well! I'd love to learn more about how the multithreaded code is actually used by professionals. Thanks for this video!

    • @git-amend
      @git-amend  หลายเดือนก่อน +4

      I'm sure we'll talk more about that soon on the channel!

  • @techdave99
    @techdave99 หลายเดือนก่อน

    Only part way through the video and already know that I will need to watch a few times. Looks like something I can use, once I understand it.

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Yes, spatial hashing has many applications! You got this!

  • @TrentSterling
    @TrentSterling หลายเดือนก่อน

    Huge area of interest for unity devs who want to make a game that doesnt explode potatos! Love it!

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Thanks!

  • @bodardr
    @bodardr หลายเดือนก่อน +1

    Hey huge fan of your videos, your code quality is simply the best out there. Quick question, wouldn't Hashsets save us from doing a binary search to get the proper cell?

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Good question. In this case, we're not just doing a simple lookup to check if a particle exists in a specific cell, but rather we need to retrieve all particles that belong to the same hashed grid cell. Since HashSets don't allow for storing multiple values per key (like particles in the same grid cell), they'd be ineffective here.

    • @bodardr
      @bodardr หลายเดือนก่อน

      Oh right, of course! And this allows us to get multiple and is of log(n) complexity. I missed out on that on the first watch, thanks!

  • @frontalachivment3604
    @frontalachivment3604 หลายเดือนก่อน

    Another day, another good video above youtube unity level.

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Much appreciated!

  • @isleeg
    @isleeg หลายเดือนก่อน

    Now you changed the saturation of the font color, I really prefer the the more saturated font color that you had in your previous video!

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Interesting, I was wondering if anyone would notice. Thanks for the feedback.

  • @Thimas
    @Thimas หลายเดือนก่อน

    Thank you so much for this tutorial! I just started using ECS with Jobs a month ago, but I had a hard time figuring out how to use Jobs with normal MonoBehaviors and such outside of the Entities Systems, so this really helped me. Would love even more of this style of performance-oriented videos. Just for curiosity, how do you paste all those lines of code so quickly in your tutorials - do you have another IDE open with it on your other monitor or some kind of Clipboard addon? Looks very smooth!

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Glad you found it helpful! The pasting is just the magic of editing!

  • @ThorBonde
    @ThorBonde หลายเดือนก่อน

    what a delicious guide, please make ore guides on unity dots, jobs and burst

    • @git-amend
      @git-amend  หลายเดือนก่อน +2

      Yup, one of these days. We'll see how many subscribers are interested in Jobs and Burst first I suppose.

    • @SA-lk6lv
      @SA-lk6lv หลายเดือนก่อน

      @@git-amend An in depth video just focusing on Jobs & Burst would be great bro

  • @nickolasbrown2260
    @nickolasbrown2260 หลายเดือนก่อน

    We need more dots tutorials from u . Its soo hard to start with 😫

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Yup, one of these days we'll work up to some full blown DOTS.

  • @Hellishcaos
    @Hellishcaos วันที่ผ่านมา

    Wondering how this would be executed in Unreal Engine 5.4. Super awesome implementation anyway

  • @-moristan109
    @-moristan109 หลายเดือนก่อน +2

    As always add a like first then enjoy the content

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      I appreciate that

  • @Flaming_Hot_Beans
    @Flaming_Hot_Beans หลายเดือนก่อน

    Awesome, would you consider doing a video on creating super efficient voxel / Minecraft type system in unity?

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Yeah, a few people have asked already. I'm giving it a bit more thought...

    • @Flaming_Hot_Beans
      @Flaming_Hot_Beans หลายเดือนก่อน

      @@git-amend oh that's great, don't worry if it's a bit out of the scope of the channel. Great videos and content 👍. All the best.

  • @ZombieChicken-X
    @ZombieChicken-X หลายเดือนก่อน

    Oh look at that I just dropped a comment on the previous video about some possible topics and then a video drops on Jobs and Burst! sweet!

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Boom!

  • @techdave99
    @techdave99 หลายเดือนก่อน +1

    I have this crazy idea of trying to combine the jobs and burst used here with the Octree video of last week. Don't know if it's needed or useful though.

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Well, the useful thing about Octrees is that you can disregard huge areas of the 3D space, so it's not quite as useful as with a discrete grid. But it can still be done of course.

    • @techdave99
      @techdave99 หลายเดือนก่อน

      @@git-amend Ok. That makes sense. Thanks.

  • @AryanSingh-cw6ce
    @AryanSingh-cw6ce หลายเดือนก่อน

    hi, Its very good video , easy to understand as always ,Question: Please tell how can i check how much memory i have and is utilizing by using burst compiler as it uses direct memory allocation ? Never used it before and it's still scary for me right now 😊 .

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Maybe we'll do another video on memory in the near future...

  • @yelo2k134
    @yelo2k134 หลายเดือนก่อน +4

    One thing to mention is that you could use TransformAccessArrays to read and write transform data and skip the step of converting it to native structs, as well as having to write to the transform once the job is completed. Also, it would be great if you showed the profiler at the end to show how performant the jobs are, in small cases like this you're probably spending more time rendering the spheres, accessing their material properties and changing their transforms. If you were to bump up the sphere count to 5000-10000 then you'd probably only spend 5% of the frame calculating the job.

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Great point! Using TransformAccessArray is a solid optimization suggestion for directly reading and writing transform data without the need for conversion, especially for jobs that manipulate a lot of transforms. I’ll definitely consider incorporating that in a future video-thanks for bringing it up!

    • @zorglug
      @zorglug หลายเดือนก่อน

      TransformAccessArray has a ton of weird quirks IIRC, like not being able to process sibling Transforms in parallel and you have less control overall. It also contains the full matrix data of the transform, which is likely to be less cache efficient than custom data (speaking of which, I would split position from velocity and radius for that same reason since only one of the particle jobs uses the latter two). My hunch (haven't tested) is that it's better to keep the struct data for the updates and sync back using TransformAccessArray in a non-parallel Burst job; but I could be wrong about this. Definitely worth profiling! I'll try to remember to test when near my computer.

    • @zorglug
      @zorglug หลายเดือนก่อน +1

      Quick update: it doesn't change too much performance-wise with this setup and TIL that there is no easy way to do transform jobs single threaded. The main advantage I saw is that updating a bunch of float3 is a bit faster and you can schedule the transform update in parallel with the hashing and querying. All of the time is still lost on rendering anyway. But I got the full jobs time from 0.6 ms to 0.45 on my machine with 10k particles. Biggest gain was removing the custom sort job and using hashAndIndices.SortJob(). I also made more gains by changing the batch sizes than by futzing with the TransformAccessArray stuff. YMMV, of course.
      *edit: Forgot to mention that both versions using TransformAccessArray were ~20% faster than when not using it. My point was that separated or not didn't make a huge difference.

  • @damonfedorick
    @damonfedorick หลายเดือนก่อน

    Nice!

    • @damonfedorick
      @damonfedorick หลายเดือนก่อน

      769,721 views, almost 1 Million.

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Hard to believe... maybe before the end of the year...

  • @turkaytandogan439
    @turkaytandogan439 7 วันที่ผ่านมา

    Sir i am making 3d mobile game that a lot of enemies following player so i wanna make enemies avoid eachother certain distance. Can i make with this system ? Can you give me some info please if its possible ?

  • @lavatasche2806
    @lavatasche2806 หลายเดือนก่อน +1

    Hi cool video. It would be nice to display the fps alongside, since this is a technique for better performance.

    • @git-amend
      @git-amend  หลายเดือนก่อน

      Thanks for watching!

  • @SeriousNeko
    @SeriousNeko หลายเดือนก่อน

    Is Binary Search faster for this case than a Hashmap?

    • @git-amend
      @git-amend  หลายเดือนก่อน

      I think this would be dependent on your use case, and if you wanted to go with a Hashmap you could consider using the NativeMultiHashMap struct.

  • @ferdinandkasangati5089
    @ferdinandkasangati5089 หลายเดือนก่อน

    Hey my brother, I felt completely lost 😂👌
    Could really be helpful having an Optimization video and Burst/Jobs tutorials in simple stuff first then we'll know how to implement the knowledge in our programming life

  • @GuiLei010
    @GuiLei010 หลายเดือนก่อน

    🖥

    • @git-amend
      @git-amend  หลายเดือนก่อน

      👍

  • @julianemery718
    @julianemery718 หลายเดือนก่อน

    Didn't Unity do some really shady stuff recently?
    Something about changing their rules so for any game made with it, the devs of said game had to pay unity a little bit of money per download?
    Not only that, they made it retroactive so even before the rule change the devs had to pay for every download of their game, period.

    • @git-amend
      @git-amend  หลายเดือนก่อน +1

      Unity no longer has a runtime fee, they've thrown that idea out.