Tutorial: AI - Pathing cost - Unreal Engine 4 + Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to this tutorial where we will be continuing to delve into artificial intelligence by looking at path finding cost so let's jump into it and see how this works so here we are inside of unreal engine 5 this is early access 2 and this will be very similar in unreal engine 4 as well so essentially what we have already prepared here prepared here is that i've made a little level it's a very simple level just so we have something to navigate around with we have an ai which is being controlled and has a very basic behavior tree the only thing it does is it goes after the player and when it reaches the player it waits for four seconds and then it starts chasing it again so that's essentially what this does and to demonstrate it this is what happens so it just runs up to the to the character stops and then continues and that is all that we need for our purposes today to learn about pathfinding costs so whenever a ai decides that it wants to move between two different points it takes into consideration its environment so if we were to press p you get to see our nav mesh and for this to be useful we want to see the nav mesh costs in unreal engine by default this is turned off in unreal engine 4 i believe this is turned on regardless you can go to edit and project settings and then you go to under the engine category you have navigation mesh and here we have draw volume costs if we mark that one and we go back out you can see that we have these areas which have a cost default fixed and then some numbers next to it so the number to the left is essentially pathfinding cost and you can see that all of these different areas all have the same cost they're all showing as one so when an ai wants to move from one point to another it takes into consideration these different costs in these different areas to make sure that it is going um with the path of least resistance sort of um it will take into consideration that if there is a strip of area that is lower cost to traverse it will most likely use that as long as the traversal area is long enough for it to gain benefit from that instead of going the straight direction to whatever object it's going for now there are a bunch of different ways that this is determined the navigation mesh that we have to begin with as i said has the cost of one which is default but you can also bring in other volumes to affect this value so if we go to create and we go to volumes you can see that we have something that's called a nav modifier volume we drag this out and you see that we have this little box here now this box by default has something that is called a nav area null class connected to it so an area class will determine what kind of a cost is associated with the area that is covered by the volume so to start off you can see that this volume is covering this area of the ground and this area has become gray the reason for this is that this nav area null will act as an area where it's not allowed to move so if we were to scale this for example you'll see that it will exclude more of the nav mesh that the volume is covering so this is has essentially become areas that are now off limits for this ai to walk through so you can see that it's taking let's by pressing apostrophe we can see our different damages you can see that if we place ourselves somewhere he will go around avoiding this whole gray area in the middle because that's not allowed area to walk on and you do have a few other default dab area classes you have a default which is just going to be the same as everything else so it's going to be a cost of one you have the null that we talked about earlier we also have a low height which is you can see it has a really weird cost here and this one is presumably used for determining um areas that you can crouch into and such you also have something that's called nav area obstacle and if you walk in closer to the the cost you can see that it has a value of i think it says 1 million or 10 million something like that a lot of numbers at least and you can see a different colored area in here so these are the default ones that we have available to us if we want to exclude areas within the nav mesh make them more difficult to traverse and such things to begin with let's demonstrate this expensive one if we were to rotate this and this is an example that i'm replicating from the the unreal engine documentation just to prove how this works so we currently have a wall over here which goes from this wall to this wall over here the only opening is over here where we have placed this volume that now has this cost of one million which is quite a lot more than one this is however just a determination used for a determination of to see which path is the best path if an ai however is only able to reach us if we're standing over here and the ai is over here this is the only path to reach us doesn't matter that it costs a lot it's still the only way that it can actually reach us so it will still walk through so let's demonstrate that by walking past the ai when it has stopped and placing ourselves over here you can see it will walk over here handy dandy no problem to demonstrate that this does have an effect though what we can do is we can make an opening in our wall something like this you can see we now have an opening over here so if we were to be over here and the ai is over here it will determine that this path is way too costly to reach us and it will instead walk around here where the costs for the pathing is much lower so let's demonstrate this quickly you can see the character is running around so that is how this works you essentially can create areas where you want to discourage an ai to move through or encourage an ai to move through by having different costs associated with the area that the volume is covering and the purpose to do such things would be something like yeah maybe you have a train track and you you want to make it so that the ai appear to be cautious about their environment they don't want to jump on our train track because they can get run over by trains or maybe you want the ai to more commonly walk certain paths when it's patrolling or something like that then you can put in areas where you put in lower costs making sure that it will spend more time in those areas than other areas because it will try to find the path of least resistance sort of so these are all good and fine but you have the option to make these yourself to tweak the functionality a little bit or the the the cost for them and it's very easy you just go to create a new blueprint class and you open up this little all classes and you type in [Music] nav area you can see here we get all the classes that we have as default to begin with but we can just choose nav areas are apparent and we can call this bp nav area expensive for example and then we open that up and this is what we're greeted with so it doesn't contain a lot and essentially all that we have is that's of importance is over here we have a draw color which will be the color um that is going to be displayed on the floor for an area that is using this nav area we have a default cost which is going to be representing this cost that we see over here that's by default one and 10 million or one million over here in the expensive part and we also have a fixed area of entering and this is a cost that is taken into calculation like let's say you had something an area that was very easy to traverse it had a low cost so let's say it was uh asphalt or something like that but around that asphalt you had a moat dug or something like that some kind of trench or a ditch making it difficult to traverse up to the asphalt what you could do is set a low default cost making it um very cheap for an ai to move once it is on that area but have a steep entering cost to make sure that it takes into consideration that getting to the asphalt is not easy and as such this should be taken into consideration as well when it comes to calculating which is the best path to take anyway so what we can do is you can find some kind of way to color code your areas being easily distinguishable if they're expensive or not so maybe red might be a good color for something that's expensive and if we were to put something like 100 in here how you use this is we save this and we take another one of these volumes like we had over here and now that we have created this blueprint over here we have available to us over here now a bp nav area expensive so if we set that you can see that we get the color that we had chosen and we can also see our number here 100.000 so now this area over here is considered expensive and if we were to you can see it's already trying to avoid this area as much as it can because it's very expensive to it so this is how you can tweak and make numbers more and less appealing to walk over or walk through so this will be the representation of whatever that the area that volume is covering in addition to making things expensive you can also make things cheap so if we duplicate this and we call this nav area cheap so when we open that up we can go and take a different value that's below one so if we were to take 0.1 for example and then we change the color to maybe yellow just so we have something to distinguish from the normal green i was thinking and then you drag out that's not what i wanted to drag this volume copy that we change the blueprint to the cheap one you can see that this area is now affected by the cheap one which means that if our ai finds itself sort of nearby this area it will be quite inclined to see if we can position him so if we place ourselves over here now you can see that it will run towards the the yellow area to traverse house rather than the the direct straight line that he actually had available to him so i hope that made sense this is essentially how you can manipulate your ai movements in certain paths or keep them away from certain areas and also make it so that it feels like the ai is taking into consideration the actual terrain it is walking through by having these numbers tweaked to represent something that would make it likely in comparison to the normal default one values yeah hopefully found this video helpful if you liked the video leave a like if you did not like it leave a dislike leave any suggestions or comments you have down below subscribe and share this video if you want to see more like it in the future that is all for now keep on learning take care [Music]
Info
Channel: LeafBranchGames
Views: 9,669
Rating: undefined out of 5
Keywords: Unreal Engine 5, Beginner, Tutorial, Unreal Engine 4, Game development, AI, Artificial Intelligence, Pathing cost, Nav area, Nav modifier volume
Id: sHvriqpc3qE
Channel Id: undefined
Length: 14min 15sec (855 seconds)
Published: Tue Oct 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.