Watch this if you've never tried JOBS in Unity (Tutorial)

  Рет қаралды 12,828

Sasquatch B Studios

Sasquatch B Studios

Күн бұрын

Пікірлер: 37
@madpingui5007
@madpingui5007 3 ай бұрын
Awesome video im just starting in JOBS system! Few fixes i can potentially see: 1. you dont need to do complex math to get the direction angle to the player you can just do lookRotation = Quaternion.LookRotation(Vector3.forward, direction); direction being the positions substracted normalized, that saves math calculations in all 15000 units. 2. There is no need for IsDone since awake always happens first than any update. 3. TransformAccessArray should be Disposed on OnDestroy ideally. 4. Also there is no need to create a _enemyTransforms, you can just _accessArray.Add() every enemy once its instantiated. Hope this tips help a little bit. Thanks!
@Noixelfer
@Noixelfer 2 ай бұрын
Also, you can calculate the distance first and use it to get the normalized vector a bit more efficient (by dividing PlayerPos - transform.position to the distance). And considering that most of the enemies will be outside the given range, you can do an early exit by comparing the square magnitude towards the enemy and only rotate the enemies that are far away.
@naolshow
@naolshow 7 ай бұрын
The overhead at the end is not from job side, you are not disposing the rotation native array. And also you should not allocate and dispose the arrays each time since you are using the Persistent allocator, so either keep their reference by creating them at awake and disposing them in on destroy or simply allocate them and dispose them in update with a temporary allocator.
@RobLang
@RobLang 7 ай бұрын
Really cool overview. Really appreciated the look at 15,000 individual jobs because I think the overhead would catch many out!
@majin2909
@majin2909 7 ай бұрын
I know you since 1k subs, I am glad u didn't gave up and are that far on youtube, hope you are making a good living now, at least good enough to survive
@b5fan504
@b5fan504 7 ай бұрын
A good video. I suspect some people may benefit from clarity that, essentially, every time you say 'thread' you could say 'core'. That's what you're allowing here; to spread more work across more CPU cores. I also like that you touched on their being no free lunch; it comes with its own overhead as everything does.
@bcreusot
@bcreusot 5 ай бұрын
Side note on performance improvement, (the rotation not being disposed and persistant have already been addressed). You should swap using Distance for DistanceSquared (ie : comparing the squared distance instead of the normal distance). The normal distance, include a squareRoot in its calculus which is def more costly that squaring the constant you are comparing it to.
@OIndieGabo
@OIndieGabo 7 ай бұрын
Just to add my take on "why 2 libraries for Jobs exist" and also why we keep seeing libraries (namespaces) with the same name. I am not sure if this is exactly the case but the JOBS library is an isolated solution. It might not necesserally been written to work solely for the UnityEngine. It is a solution on multithreading in a specific scenario. So you have the solution "Unity/Jobs" (using slashs so youtube does not mistake it with a link). It contains everything to make Jobs work. And then you need an implematation that actually takes advantage of that system and applies its usage in the way it needs to its own solution. That's why you have the "UnityEngine/Jobs". It is basically the UnityEngine having an implementation on how to use the Jobs library, wich happens to be made by Unity (the company).
@magnusm4
@magnusm4 3 ай бұрын
I love JOBS and the GPU based VFX Graph along with burst compiler and such cause it's both an optimization but also a fun and rewarding challenge to learn while making a game. But the best is what you show in the beginning. Lots of stuff. You can make a simple 2D or 3D game but the scale of your particle effects and size can be impressive and still performant. It also makes smaller projects much easier to not get stuck on optimizing and less punishing for it.
@TheKr0ckeR
@TheKr0ckeR 22 күн бұрын
Great tutorial about Job system! I have a little unrelated question. How is the batch count is very small? Do you use GPU Instancing or smth like SRP batcher? If so, There is almost 14K saved by batching, what doest it affect? I'm pretty sure there is some trade-off on that, whats happening on saved batches? I mean even if we have 25 batch, Im not sure what happens to the saved batchings, more load on GPU?
@bitgridgames
@bitgridgames 7 ай бұрын
Okay.. Im going to give this another shot. I need to start showing viewers how to make cool games and get more viewers. tough. Great video man
@muspuxx6866
@muspuxx6866 2 ай бұрын
Why, at the end of the video proving it's ineffective, do you use an array but only utilize one element?
@TheArghnono
@TheArghnono 7 ай бұрын
Excellent tutorial!
@Dragoncro0wn
@Dragoncro0wn 7 ай бұрын
Is it a bad idea to make the thread function like an update loop? Always running in the background doing its own tasks
@HumanityAsCode
@HumanityAsCode 5 ай бұрын
You would probably run into a race condition doing that
@HumanityAsCode
@HumanityAsCode 5 ай бұрын
Isn't this ECS with more steps? If you're operating on a list of 'entities' as it were why not skip the job and go full ECS
@k-6353
@k-6353 6 ай бұрын
Hi, I've seen JOB system when I started using Unity but i thought it was way too advance for me (i still do). All in all, Does this mean i cant implement JOB system into AI bots? or is there another way to optimize? Currently, I reach 20fps after spawning nearly 100 AI bots, equipped with Movement(patrol, chase many more), Combat etc. I get 15 fps with 350+ bots with their main AI script disabled. Would be greatly helpful if someone could lead me into a direction
@danielwertz8724
@danielwertz8724 7 ай бұрын
Im a godot developer but love your videos. Feel like i still got a little out of it. Helps that I use c# in my day job and use threading frequently. Thanks for the vid!
@redragon1229
@redragon1229 7 ай бұрын
Cool video. I want to point out that although the ~x2 boost in your example does not look that impressive, actually, excluding rendering and other processes, Jobs can be HUNDREDS of times faster than the same single-threaded calculations. In this example the difference is not so significant because, I think, most of the performance hit is the rendering. Also, as @naolshow pointed out: this can be further optimized.
@AliHosseiniDev
@AliHosseiniDev 7 ай бұрын
Oh boi that was a nice explanation.
@dawid6211
@dawid6211 Ай бұрын
As far as i know, it is a bad practice to call Schedule() and Complete() on the same frame
@rrainix
@rrainix 6 ай бұрын
How are you instaniating 15 thousand enemies so fast?
@lightbug6103
@lightbug6103 4 ай бұрын
Why are you using that _isDone flag? Regarding the MonoBehaviour code, there are small things that can be changed in order to improve performance: 1. Using a list of enemy transforms instead of GOs, so you don't need to access the transform for the 50k enemies. 2. Grabbing the player's position before entering the loop instead of calling "_playerTransform.position" every time. 3. Using Tansform's "SetPositionAndRotation" instead of ".position" and ".rotation". 4. The following operation "direction * dt * moveSpeed" can be rearranged to improve performance like this: "dt * moveSpeed * direction" or just "direction * (dt * moveSpeed)" 5. I know Time.deltaTime is not a big deal, but I usually cache that as well. I'm not saying this is gonna beat Jobs, but it could make a difference nonetheless.
@user-uk9er5vw4c
@user-uk9er5vw4c 6 ай бұрын
nice content, thanks!
@privatdetektivenkant5975
@privatdetektivenkant5975 7 ай бұрын
Give me more!!!!!
@PhiLudo
@PhiLudo 7 ай бұрын
cool stuff
@정동우-n2x
@정동우-n2x 7 ай бұрын
I love it
@Coco-gg5vp
@Coco-gg5vp 7 ай бұрын
First
@GostGostcic
@GostGostcic 7 ай бұрын
this video is so bad, he could make this code 10x faster with jobs but he made so many mistakes in the video lol
@OIndieGabo
@OIndieGabo 7 ай бұрын
This comment means nothing if you are not pointing out how the solution would actually be improved. There is no harm on pointing mistakes out and explaining them so everybody can grow on it. What you did here is just offensive. And if this is was your intention it becomes clear why we should not listen to what you are saying and just ignore you in the future.
@GostGostcic
@GostGostcic 7 ай бұрын
@@OIndieGabo [ReadOnly] works only on native containers not the normal variables, boid Transforms should have null parent (this is extremely important) and updated only with TransformAccess.SetLocalPositionAndRotation(...), then he should show profiler because this is not the bottleneck (because can handle 100k+ updates per frame easily), he is doing something else wrong. i could go on... but the point is, dont watch this, he is missing the point of the JOBS and what they do.
@ehabelbwab1783
@ehabelbwab1783 6 ай бұрын
@@OIndieGabo Agree
@urirat3750
@urirat3750 21 күн бұрын
How? im learning job system but if you just comment without pointing out the solution it means nothing.
@GostGostcic
@GostGostcic 21 күн бұрын
@@urirat3750 i cant fucking teach you in a youtube comment. i would advise you dont just copy paste code. TEST IT out, see how fast it is and WHAT makes it fast. definitely learn to look at generated assembly code, you have tools (viewer) for that in Unity already.
@frankrenzulli4354
@frankrenzulli4354 6 ай бұрын
I CAN'T FKING HEAR YOU, TURN UP YOUR VOICE PLS :(((((
Make a MiniMap with NO CODE (Unity Tutorial)
8:46
Sasquatch B Studios
Рет қаралды 3,5 М.
Get started with UI Toolkit in Unity
12:29
Sasquatch B Studios
Рет қаралды 52 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
#behindthescenes @CrissaJackson
0:11
Happy Kelli
Рет қаралды 27 МЛН
Unity Job System - A Practical Code Example
13:50
Infallible Code
Рет қаралды 83 М.
INSANE shooter with WAY too many bullets (Unity ECS Tutorial) - PART 1
15:20
Sasquatch B Studios
Рет қаралды 12 М.
Volleyball (Kinda) Final Part 5: Code the Ball
26:28
Bananahead
Рет қаралды 117
The MOST WANTED Unity Feature is FINALLY here!
12:15
Code Monkey
Рет қаралды 53 М.
OPTIMIZE your Unity game using these performance tips | Tutorial
11:20
Sasquatch B Studios
Рет қаралды 24 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 826 М.
The Unity HACK that the PROS know
21:27
git-amend
Рет қаралды 18 М.
CLEAN Game Architecture with ScriptableObjects | Unity Tutorial
13:12
Sasquatch B Studios
Рет қаралды 20 М.
UniTask: How It Replaces Coroutines, Tasks and Awaitable
24:49
134 Unity Components EXPLAINED in Less than 30 Minutes
24:01
This is GameDev
Рет қаралды 75 М.