Unreal Engine 5 - How To Spawn Actors/NPC's In Your Level. Beginners Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm going to be showing you how to make an AI spawn system so this AI spawn system is going to shoot out a number of AI in different locations of your map or your level or wherever it may be so here we have just our third person character again nothing special going on about it we're going to add to begin with a actor so this is going to be ENT our where do we want our wave to spawn so spawn locations ppor spawn location and all this is going to be is we'll just get billboard hitting game and take that right so all these locations are is things we can dot around the map that we want the AI to spawn from so we'll just check a few out now check one there check one there so for that that's it what we're going to create now is our spawn system our wave system if you will it's going to be BP underscore spawn system so here we have our blank blueprint for now what we want to do is essentially spawn actors at that location so the way we'll do that is we'll create a function called get spawn locations and all we're going to do is get get actors of class of bpor Spawn locations and then add that to an array make that an array so we'll call this spawn [Music] locations so we can leave that as that but we'll just add a return value here and we'll just put that through so locations so all we're doing now in our system is when we call this event it's getting all actors of class so getting all the actors within our level that are BP spawn locations for each of them we're just going to add them to we're just going to make an array out of it and return that so now we have our locations got we basically want to create system spawning AI in so how do you spawn AI well spawn not that one spawn actor from class this is the way you normally or allowed spawn stuff in what you want to spawn in is our AI for this we'll just use bpor third person character um that's going to be the class we're going to be spawning in um I haven't made any special AI or anything like that um but we might want to control how much we want to spawn in and stuff like that so how do we do that well add custom again so this is going to be spawn NPC so when we call spawn NPC going to go for each loop we're going to spawn our class obviously we need we need our collection of AI so what we could do for this um quick tutorial is basically set up a reference called this NP NPC to spawn um of type array that's fine and we can make that instance editable for later on when we have to put in the map so back to this so we need our transforms well luckily we have them CU When we call this what we'll do up here a event begin play to make it easier we're going to be getting our spawn locations and we have them here I did create a I did already create a reference to them so if we wanted to call it down here we actually could we'll do that there so we can um make sure our event is definitely cool to begin with so when our events are called We're get in our spawn locations and then for each Loop we're getting our NPC to spawn and spawning them we just need to set where so what we'll do is from this we'll drag out from our uh array here um a random array from item plug that sorry we we got a we got our item we need to we can get transform and we can plug it in there don't need an [Music] instigator there we go just refresh that we just Swap this to always [Music] spawn so our spawn system here now uh all we'll have to look at is our NPC to spawn so we'll just add a few in oh sorry what I forgot to do is within our spawn system we actually we we've got it to at the minute um which is fine but you might it might be more specifically a a blueprint class so for us we have bpor third person character that's the class we're going to be spawning in so what we'll do is we'll change it to that compile save and then when we refresh this we'll delete this out we'll put a new one in and we add some more well we should be able to I bring this back down here see it's hidden a little bit if I just bring this out here we can add our third person character there and we add some more so we have seven spawning so if we hit simulate now we can see that it has filled them all all of them have been filled now what you might notice is um then I was borning because of the uh collisions um so what we'll do is just within here for now we'll turn off collisions on our character of typ porn that we hav't ignored lovely so they're all spawning now we go some of them are just hidden under each other cuz we've set it to do that um what we can actually do is set that to um a block it might push them out the way so so we'll just set back so that it's working so that's just a simple way of setting up a NVC spawn system where all it's doing is spawning the PC at a a random location that we've got from our transform uh we just quickly editing it we can make it if we wanted a bit um more random um by making it so we can only go to that that if that spawn location has been chosen pick another one um but for this quick tutorial I just want to show you how you can get out spawning AI um in different locations like so and then if we want to add more we simply come to the manager add some more into the array like so and we'll hit simulate and there we go more AI in our level now obviously You' have them on their own AI controller with their own Blackboard and behavior trees doing stuff but spawning in the level quite simply starting it starting this event getting all of our actors then for each one getting a random spawn location so and if just before I do leave if you want to just make this a little bit better what we can do is we can add this function over here we don't actually need the uh return value there because what we can do instead is just get our reference to that just make our code a little bit cleaner there we go so thank you for watching this very quick tutorial to show how you basically get NPCs to spawn in your game thanks for watching and see you on another [Music] [Music] video [Music] a
Info
Channel: That's Unreal
Views: 381
Rating: undefined out of 5
Keywords: unreal engine 5, unreal engine, unreal engine tutorial, tutorial, how to, spawn acotr, NPC, AI, how to spawn AI, beginners guide
Id: fmLSRVlDtow
Channel Id: undefined
Length: 10min 6sec (606 seconds)
Published: Tue Jan 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.