Unreal Engine 5 AI Tutorial - Understanding EQS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] thank you what's going on everybody James here from artificial entertainment and welcome to another Unreal Engine 5 tutorial and today we're going to be looking at the environmental query system so let's go ahead and dive in so I have here a third person project I've created a simple AI uh just a controller Blackboard Behavior tree all that stuff there's nothing the eqs related and there's nothing in the behavior tree either it's all empty so we're going to be starting from scratch I just created the base components and so what we're going to be doing today is I want to go over the eqs system now I'm going to go over all the generators different things that you can do with them and then show some demonstrations of things that you can do as well because realistically the environmental query system is something that is truly amazing there's so many things that you can do in so many different detections you can set up for your AI that I really wanted to kind of do a better video um about how to be able to really utilize different pieces of this system now one thing just to state is that this is an AI function this is something for NPCs for AI this is not for your player character so this is the reason why I just set up a simple AI if you guys are interested in learning how to be able to make AI I have a series on that and I'll put a link at the bottom of this video but today is all about that eqs so let's go ahead and get started and start talking about what it is now the basis of what an the eqs is is that it's a generation of detection of multiple different styles that can return back either an actor object or location value now this is very powerful because it's something that is a constant run but runs a lot more effectively than something like an event tick function and it runs usually inside of the behavior system which makes it even better so let's go ahead and make our first eqs so I can stop stop talking about it and show you guys a little bit more so to be able to make one all you got to do is right click go to artificial intelligence and click on environment query and then we'll just name this test eqs and then we'll double click and open that up now one thing you'll notice when you open it up is that it does look very similar to a behavior tree now the reason why this is because well it's meant to function very similar to a behavior tree but when you pull off the root you're going to notice that you have a list of generator and even though this might say composite it doesn't work like a composite inside of a behavior tree and we're going to go over the composite one last just because you need to really understand the rest of these before you're really going to start jumping into this so the first thing we're going to talk about is probably the most simple of them all which is the actors of class so the actors of class query what this is is essentially allows you to be able to generate in a radius a detection to see if there's any type of specific actor or any actor type or object type or anything that you're really looking for and that can all be changed under the details panel under generator go to search to act or class and you can change it to any actor type or blueprint type or a whole bunch of things in all honesty you have skylights you have a whole bunch of different things that you can actually have it look for now you can also have it just look for it on like across the board but you can also make it so it's only going to generate actors in the radius that you set which you can set from this value here 500 is usually a good starting value but depending on what you're trying to do you might want to increase or decrease this and then as well on this you have the Research Center now this by default is going to be whatever the AI character that's going to be initiating this query is going to be but you can make your own context queries so that way you can have it search or start from a different location we're going to talk about making your own contacts here in a little bit but I just want to let you guys know that you can use this to be able to generate a list of actors around the AI around another object and honestly it limits your imagination so that's the actors of class very basic very simple and the next one I want to talk about is going to be the perceived actors component now we used this in the AI series when we made the detection system and the reason why I like to use this is because it's basically a detection component that is going to be built into the behavior tree rather than being coded into the controller I have found that this is a lot more effective when trying to spawn multiple AI if you have it all running through the behavior system so that's the reason why I like to use this node as the controller for setting of certain values based off of if we do or do not see something now the one thing to keep in mind if you use the actors query is that you need to make sure that you actually have the environment or the AI perception component inside of your controller so if I open up the testing AI controller you're going to see I have ai perception I don't have anything in it yet but actually I will go ahead and put in the site config just really quickly because we are going to want this later so we'll go ahead and just do a texture by affiliation select everything max age of one and then we'll just compile and save that now again you want to make sure so if we're going to set up something that allows us to have a detection of sight for example so if we go back to our eqs here we can actually set the sense to use to whatever we want so if I set it to AI send site but I don't have site listed on my controller this will not work because all of the information that this query is going to use for its detection is actually going to be based off of the AI perception system inside of your controller so all of this information here is still going to be used it's just going to be rather than going through the controller it's then going to be pushed into this eqs and used here instead now this is very important to know because the next option up here that I want to talk about is the search radius so negative one means that it's going to reduce the value with a cone that's going to go out for the AI sense of sight now what this means is that it's going to reduce it I don't really know what the exact value systems are for the research radius um but from what I've seen I'm estimating that it's right around negative one is going to half size it zero is going to make it so that way the cone is the standard normal size or whatever settings you set it within the controller here uh one would be doubling it two would be tripling it this is sort of what I've discovered so far I have not been able to actually approve of whether or not this is 100 accurate but it's reasonably accurate to go by so negative one is going to reduce it by half and then zero will just make it so that way whatever settings you have inside of your actual perception component are going to be what it runs off of now and just like all the other ones here we have the loud actor of class we can set this to just any act or type that has the AI perception stimuli Source component however we can also set it to a simple BP third person character if we wanted to because this way we can have it so it just detects the player character so you can have this set up so that way it's going to detect very specific blueprint actors or any actor that is or any blueprint that is of an actor your type or any other type that you that you're really wanting to look for but again the main thing to remember is that your AI has to have the stimuli component and the thing that you're trying to have it detect has to have the AI perception stimuli source so those are two very important things that have to be in there in order to make this work but as long as you have those you can use this very easily now the last one I want to talk about before we start getting into actually how these get put together I am going to talk about all of these but like the point's great it's better it's a different system we're going to use to show you guys that so what we're going to talk about now is going to be the current location now the current location is actually very very simple like I said in the beginning the eqs can return either a actor list or a vector location list but that is it one thing to keep in mind is that most of the time when you set up an eqs it'll return a type of an actor however this is a specifically a location value based off of whatever context that you set so this is the reason why I wanted to go into this next because this allows me to be able to kind of explain how contexts work within the system for the environmental query so so now just a quick overview as to what this is is literally just Returns the current location of whatever it is that you're setting as the query context so what we'll do is we'll go now and make a context for our eqs so I'm going to go to my eqs here I'm going to right click and I'm going to go to blueprint class now what we're looking for is we're going to type in context and we'll see EnV query context underscore blueprint base so this is what we want the environment query context and we'll take the and just name this player context now if we double click and open this up and we go over to the my blueprint section under the functions you're going to see an override option and this allows you to be able to provide a single actor or location or as well as a array or multiple locations or actors so this is where location actor set or single actor single location now what this means is that if you're using multiple actors you need to have some sort of an array function or something like that but a single actor is all we really need when we're using for like the player character and it's just a single player game now as you can see here we have the query or object query actor and then resulting actor nodes here now all we really need to do is we're going to pull off the resulting actor and then we're just going to get player character and we'll go ahead and slide this back just like so and what it'll do is it'll the resulting actor will just be our player character which for us is going to be the BP third person character now what this is going to do is allow us if we go back to our eqs we can now go the query context we can set this to players so now what this will do is return the current location of our player so we'll start with this one we'll save this and we'll go to our AI Behavior tree now what we're going to need is a vector location key in our Blackboard because again this particular eqs only returns a vector does not return an actor set so what we need to go is new key scroll down to vector and we're going to type in player location and then what we're going to want to do is go to behavior tree off of the root we're going to add a selector and then we're going to add two more selectors one on each side because we're just going to set it up so that way if the eqs finds something it'll shoot off to one branch and if it doesn't it's going to shoot off to a different branch and if you guys watch any of my AI videos you know how we're going to do that it's going to be just through a simple Blackboard decorator so we're just going to go to the Blackboard base condition and we're going to look for a player location is set so that's going to be the thing that it's going to look for so if our eqs sets a location value we want it to shoot over here and then what we're also going to do is add decorator and we're going to go for conditional Loop because we're going to have it execute this over and over again while player location is set then what we'll do is off of the selector we'll just move to set the Blackboard key for the move to to player location but the acceptable radius up a little bit just because it's usually really high and then after the move two we'll just put a simple weight function setting it to about two seconds because we don't want the weight to be too long now so what we've done is just made it so that way it knows where to switch it but we haven't given it the information yet so what we're going to do is to our main selector here at the bottom gray node we're going to right click go to service and run eqs now the way that this works is that whenever you put his service EQ has onto a selector it's going to run this even while it's executing these other branches so even though this is still this you know the execution might be down here it has to run through this selector so wherever you have these Services you can actually control how often or how it actually runs the information by just intelligently placing your eqs so what we can do is click on this go to the eqs request under the details panel and we're going to select our test eqs and then under the Blackboard key we'll set that Blackboard key to player location so now we'll go ahead and save and I do have a nav mesh here so we can just go ahead and click on play but now you'll see that player location is set and he's moving to me now this allows us to be able to do basically the same thing as you know setting the player location but I'm just showing you guys how this works with setting like a vector value and then setting a context you could do the same thing rather than getting the player character you could cast to something or get actor of class you know and then you could put the return value into the resulting actor like this you could select from any actor that you want this allows you to be able to get the actor of a specific kind within that value so there's a lot of things you can do by just again intelligently setting up your contexts but the one thing I do say is that if you're trying to set up something where you're going to get a location value but you might sometimes also need an object value just set it up as an object value versus a vector value so on the overrides here use single actor or actor set don't use location set unless it's only a vector value that you're going to be using and it's only a vector value that you're actually going to be saving so these are the things that you do want to keep in mind when doing this so that but that's really all this is so with the queries and the contacts you can use these to be able to set the location where the query is going to happen and then what it's going to do and then the execution for what it does after it finds that information so let's go ahead and change instead of current location let's go ahead and we're going to look at the perceived actors type so we're going to set this to VP third person character and we're going to set the sense to use to be AI sense site and then we're just going to click on Save now we do have to add the AI component to our third person character so we're gonna go VP third person character here and just open this up go up to add and then we're just going to add the AI perception simulite source and then under AI perception register as source for site compile and Save so now what we'll do is we're going to make another Blackboard key and this one is going to be an object key with the name of player we'll change the key type from object to actor now what this is going to allow us to do now is be able to get an actor value instead of a location value so we're going to set the Blackboard key to player and we'll change these Blackboard values to if player is set instead of player location and then the move to will set to as player so it's basically going to have the same function but instead of player location having a vector value Associated under the Blackboard key information down here at the bottom we'll have a player object value under here instead so if I go ahead and click play I will have to run around my AI so that's why you can actually see me because right now the player location is invalid and yeah so as you can see as soon as I got into site BP third person character underscore C underscore 0 is set as the player type I can just keep moving around you know minimize the uh thing here but yeah as you can see you know he's following me he's doing whatever he's supposed to do but now I have a Blackboard object value rather than a vector value and you don't need to use a third person character you can use anything you want you can use other like like a blueprint of some kind for like a workstation you can use anything you want with the eqs system as far as setting the specific actor values for the perception component so the last thing that we want to talk about is going to be on the eqs itself we're going to talk now about utilizing the point system now the points are essentially just it's going to generate a bunch of points around but the reason why we're doing this now versus doing it with the AI character is because it's actually an easier way to be able to really see what's going on so what we're going to do is under the test eqs we're going to add a different generator and this one's going to be the points grid generator now we're also going to go ahead and remove the eqs off of our ai's Behavior tree and take our AI out of the world completely because for the eqs now this isn't necessary but it does make testing these a much much more of a breeze so we're going to go into our assets here just so we can all stay in the same folder and we're going to go right click blueprint class and we're going to look for eqs testing and you're going to see eqs testing Pawn so we'll click on this and then click on select and we'll just name it testing underscore Pawn now what we're going to do is we're going to drag this into the world here drag it up a little bit so that way it's on the proper height and then if we look kind of scroll down under the details section you're going to see that we have an option here for a query template so we're going to change it from none to test eqs and now you'll see that we have a grid that is being generated and you can already see that the grid is actually being affected by certain things that are actually affecting the nav mesh such as this here and this ramp here now one thing that's really cool about the points grid is we'll go ahead and bring this back up here now you can change the size of this grid by doing a few different things first thing is the grid half size so we'll change this to a hundred now as you can see here 100 by 100 kind of puts it right dead center but if I go 100 by 75 you know as you can see by changing the space between it makes more or less areas of detection because each one of those spheres is essentially like its own little sphere detection right so if I go and set this to 125 you can now see that because of the space between is larger than the grid half size it's no longer in the Middle where it should be but if I set this from 100 to 250 now you can see that it's back into the center so there is a bit of a mathematical equation that happens between the grid half size and the space between realistically make sure that the space between is roughly around half of whatever the Grid's half size is and you'll pretty much make sure that your grid is always dead center of whatever you're trying to use it for so now one thing we can do with these and you can do this on any one of them all of the generators that I've shown you today you can also do this with but it's just easier to show you the visual example uh when doing it with the grids so we're going to right click and you're going to see something here that says ADD test and from here we've got distance dot tags overlap pathfinding a whole bunch of stuff here right now the one thing that's really cool is that if we go and hit Trace query or trades on visibility and we set score only and the trace data is basically what this is going to do is set up a line trace and it's only going to line Trace things that are actually going to be able to be hit by the Collision system for let's see visibility so that's the trace channel so you can use custom Trace channels in these two which is pretty cool but if we go to our BP third person character here will drag an instance of them into the world but we also need to change the Collision because right now by default the VP third person character does not collide with the visibility channel so we're going to go Collision presets set it to custom and then we're going to set it to block the visibility channel so now if I go back save now you can see that this is getting a zero because this is getting hit by our testing Pawn so if I take the testing pawn and move it you see now that's zero if I move it back it's all zero so this is basically just showing which one of these is actually being hit but there's not a lot of information that's happening right there are not really a lot of things going on so what we're going to do is change it to filter and score and now you'll see that now it's getting a result of one what we can also do is add another test we're going to add a distance check now this distance is going to be score only because we wanted to basically what this is going to allow us to do is as you can see distance to query or prefer greater so this is the queryer it's checking and seeing that okay we have their AI or our player character right here and then it's going and all right well that's a little too close we want this instead because it's going from the distance now we can also go distance to and we can choose that player context as well if we want now as you can see though it does create a little bit of an issue where these are both being scored as one now that's not entirely a bad thing um but it does make it very difficult for it to properly set location values you want these to be scored with one of them being higher than the other so we go filter and score and put it back to the item put it into the query there and then now what we'll do is set it back to score and now you can see here that we have 1.8 2.0 so now we're actually getting it to score something based off of that distance value and this distance as you can see is 3D distance we can go 2D distance distance Z so you can actually really kind of control what that distance value is going to be but it's really up to you but this is where that grid kind of comes into play by adding in these tests and just kind of telling it okay I want to get this distance I want to get whether or not it's actually able to you know detect something is it hitting any of these traces you know so like distance is just that it's the distance from point A to point B dot is um actually it the general code dot where it's I'm going to get a rotation value so this way you can return back and get within a certain interpretation value gameplay sags overlap all of these are pretty basic um like I said I'm not going to go into every single one because realistically the the query system is so complex that I could be here for about four hours showing you guys just a fraction of what you can do with the system so that's why I wanted to make a video that was more about showing you guys how to be able to you know utilize certain portions of it but how you use it and actually making it a functionable system that's on you guys now one thing to note as well is that if I go ahead and I delete this go off of the root you can see that we have Circle cone donut as well as grid and pathing grid now one thing to keep in mind is that these are all the same the circle cone donut grid these are just shapes okay that's the only difference if I put it to a circle you'll see it's going to put it out in a circle if I put it out to a donut or a cone it's going to do it into a cone so it's really just dependent on what you need for your detection as far as size and shape go because as you can see the cone goes out a lot farther with the way that it actually you know distributes its points but the one on here that is actually different than the rest is the points pathing grid now as you can see by default it comes out very large so we're going to turn the grid half size down to about 150 with the space between being 125. now as you can see the grid is going to look for anywhere that it can't go but if it can go it doesn't do anything so this is really what the difference between the path and grid because you can go path to item and use the data binding here to go query params so this way if it does actually get the path correctly you can do things with that information you can also change the nav filter as well to make it so that way it's only going to use on certain navigation meshes and the projection data this is something you don't necessarily get with any other type of query other than the grids so or not the grids the point system so these are really really good too where you can actually change the projection height up and down go up a little higher from the ground or a little lower so it's really all up to you on how you set this up now the pathfinding option this is where it gets really cool is that you can actually set the scan range multiplier to 1.5 we'll set this to three and we'll save now what you'll see is if I go in I have to be a lot closer to that object now and then if I get too close it's going to try and find one of these points here so what essentially that scan range multiplier does is that it increases the sort of buffer distance around these points so rather than having to be exactly on the point you can set it up to give it a little bit of a kind of a buffer period of buffer Vector area and this just makes it so that way you've got a little bit more room for error in case something happens so I always suggest turning the scan range multiplier up a little bit um just so that way you don't have any issues down the road so those are all the main functions now the last one that we're going to talk about is the composite node now the composite node the reason why I saved this for last is because if we click on this you're going to see that we don't have anything here we can right click ADD test and do all that stuff but it doesn't really have any information being generated because if we look over on the details panel we can actually add generators this way we can add as many as we want and we have all of the options that we would normally have right here so we can choose an actor of class plus a current location plus a points donut click on Save and that'll be exactly what will happen it'll generate a points donut with an actor class and all that good stuff now here's the problem with composites when you set up multiple of these what's going to happen is you're only going to have one Blackboard key so if we go back and look at the uh Blackboard or the behavior tree for our AI here and if I just go right click run eqs and we put that eqs back in here even with four different actual Services there are three different Services being run we only have one Blackboard key so that's something to keep in mind is that if you're gonna you can't use this to set up like five or six different Blackboard Keys being set up within the values but you can use multiple different uh queries to be able to set up the individual keys so this is you know there's sometimes a little bit of extra work but the fine tuning that you get out of using this system is so so good now so that's really it guys you know as far as the eqs system is pretty simple you're just gonna go in and try to you know give it an actor type or give it a location value and then just run that in your behavior tree now one other thing that I just want to point out is that you don't necessarily just have to run it off of a selector or a sequence or whatever because you can run the service of eqs you can run this on any of the composite nodes or actually even on a note itself on a task so you can even run an eqs while he's moving to the player so this is something you can add these to any node in the behavior trust in the behavior system and while that node is running it's going to run the eqs but you can also pull off of any of the selectors and have it run a single instance of an eqs so it'll just run it once return a value back and this way it's not a consistently updating value and sometimes that's good because sometimes you just want to have it find something and then keep that information for a long period of time even if it's not necessarily still in range you want your AI to know that it's still there well this is how you can do that by running a new eqs whenever it's near something and have me and making sure that to set that value either back or two so you can set them up off of services off of the actual Composites or you can set them up off of their own tasks themselves and you get the same options where you can choose the eqs that you're going to run as well as the Blackboard key that that's going to set so that's really it guys eqs are awesome I love them so I hope you guys found this video informative if you have any uh questions or any further information that you're looking for about the eqs functions please go ahead and ask I am looking for some ideas for different videos to do about the eqs series I'm going to be doing a one about how to be able to make an AI find cover and some other cool things but always happy for more suggestions from you guys but that's going to close it out for today guys hope
Info
Channel: Artofficial Entertainment
Views: 6,700
Rating: undefined out of 5
Keywords: Unreal Engine, UE5, Unreal Engine 5, AI, NPC, EQS, Tutorial, Detection, Behavior Tree, Blackboard, Game Dev, Game Design, UE5 AI, UE5 NPC
Id: PDPN18II6nI
Channel Id: undefined
Length: 26min 38sec (1598 seconds)
Published: Thu Mar 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.