Enemy Horde Wave System - Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another unwrenching 4 tutorial in today's video i'm going to show you how to create a horde system or a wave system so essentially a load of enemies will spawn in in waves when you kill them the next wave will spawn in you kill those the next will spawn in and each wave will increase in the amount of enemies spawned each time as well so let me hit play get in and show you what we're gonna make today so you see we start off with this one enemy i kill it then i have three spawners placed in which will all spawn two enemies in each if i kill these then even more spawning in these three spawners and will exponentially increase each time and obviously for me it's quite easy to kill them i just walk into them but that's not the purpose of today's video today it's just creating a system in which more and more enemies will keep on spawning in as you see here so without further ado this is what we make today so let me delete this code and i'll show you how we're going to do it so the first thing we want to do is we're going to create it so we can see how many enemies we have left so if we've killed them all we can spawn in the next bunch so very simply i'm gonna be doing this in the game mode blueprint so for me that's gonna be content third person bp blueprints third person game mode you just do it in your own game mode for whichever one that you have and in here we're going to do some very very simple code because all we need to do is add in a custom event an integer an event dispatcher so i'm going to do that now so i'm going to right click add custom event i'm going to name this one check enemy left because as it sounds this is going to check to see how many enemies we have left in the level or in this certain wave so to do that we need to check which is a branch so we're going to hold down b and left click to get a branch connecting that in there and the condition is going to be enemies alive is equal to zero so we can add a variable here so we hit the plus variable naming this enemy alive or enemies alive or enemies left anything which makes sense for you i'm going to change it from a boolean to an integer try and drop that in there get enemies alive and simply out of that get an equal equal integer leaving it a zero with a condition going in there because if enemies alive is not equal to zero then there's still some left and if enemies alive is equal to zero then we've killed them all and we can go on to the next bit of code the next bit of code is going to be spawning them in again but i'm not spawning them in the gamemode blueprint i'm going to create their own blueprint for that so we need to create an event dispatcher to easily communicate between this blueprint and that blueprint so i'm going to do that now so i'm going to hit the plus event dispatchers down here and i'm going to name this one respawn enemy as that makes sense for me or you can have it as spawn next wave or sworn enemies anything which you want i think for me respawn enemy makes sense i'm going to drag and drop that and hit call setting that off of true so very simply it's a custom event of check enemies left into a branch of if the enemy's alive is equal to zero and if it is we're going to call this event dispatcher of responding enemies which we'll finish setting up later on and again this is all we need to do in the game mode blueprint very very simple so we compile save and close that like so and next i'm going to set up the enemy blueprint so you can see i have this very simple enemy here all i've done is duplicated the character blueprint and made the mesh red instead of that kind of off-white color and again this is my enemy folder here i've just duplicated it named enemy ai open it up and i have this basic code here so all i've got is event begin play and then some code to make it chase the character which i'll go over in a second as well and to kill the ai all i've got is a vent hit if it's the character we're going to destroy the actor so let me go over what we need to do so in this blueprint what we need to do is update the gamemode blueprint because we just created a variable in there of enemies alive so when we spawn in an enemy i.e event beginplay of the enemy aibp we need to update that value of plus one so very simply event we're going to play we can cast to the third person gamemode blueprint or whatever it is for you just your game mode blueprint which again for me is cast to third person game mode object will always be get game mode and as third-person gamer what we need to do is get enemies alive so we get the variable first and out of that we're going to get an increment so then going to increase this by one connecting that up to there like so so very simply when this enemy is spawned in what it's going to do is it's going to get the current amount of alive enemies and increase that by one so it knows that there is one extra enemy in a level and also what we need to do is if we select enemy ai self up on the top left what we need to do is make sure that auto possess ai is placed in world or spawned so by default it is placed in world it needs to be placed in world or spawned so that when we spawn in the enemy which we're going to do later on it will be auto possessed so we'll be moving around it'll be controlled all that good stuff which we need so just make sure you have auto possess ai as placed in world or spawned there like so and then the other code i'm going to off event we can play is casting to my character and then setting that to be the target actor of an ai move too so what this is gonna do here is just make it so when the enemy spawns in it's gonna just run directly at the player always you don't have to do that if you don't want you can have it instead of random roams and if it sees the player it chases them if you wanted that but typically in games like this it's just they're just running at the enemy or you can have it so they're running at a goal post or something which the players defend obviously set this up to be whatever you want but in my example they're going to be running directly towards the player now let's also set up killing the ai so again in my basic example it's just that the character walking into the enemy but you can set this up to whatever you want but essentially this here is me killing the enemy event hit cast the dirt blasting character so however you're going to kill the enemy what you also need to do is what i'm about to do here after you've killed them you need to cast to your game mode again which for me is the third person game mode like so object once again being get game mode and so at the start what we did was we added one to the enemy's life now we need to subtract one because we've killed them there's one less enemy alive so very simply as third place in game mode we can again get enemy alive like so and now instead of getting an increment integer we're gonna get a decrement or decrement integer which instead of adding one it's just gonna take one away very simply like so and also we need to call the customer event we made of checking how many enemies we have left so if we kill one we need to see how many we have left now so as third person game mode we're going to also call function check enemy left like so to see how many we have left in the level and then after that we've got destroy actor because we killed the enemy we're going to destroy the actor as well and always make sure destroy actor is at the end of the code because anything after destroy actor will not fire off because obviously you've destroyed the actor there's no code left it's been deleted so have that at the end of your code and that is all i'm going to do for the enemy blueprint what we've got is when the enemy is spawned in it's gonna add one to the variable of enemies alive and then just make sure they're chasing the player and when the enemy dies i.e when the player hits them what's gonna do is take one away from the enemy's life and then also check to see how many enemies are left just in case this was the last one in the level so we compile save and we can close this as well as this is all we need to do in the enemy bp here and finally last but not least what we need to do is also set up a blueprint to spawn in these enemies so that's also very simple what we're gonna do is right click go to blueprint class get an actor and i'm gonna name this one enemy spawner bp you can name this whatever you like but that makes sense to me i'm gonna open that up straight away i'm not gonna add anything in the viewport because i don't need to see this it doesn't need to be visual all this needs to be is somewhere where we can spawn in the enemies you can add something in here if you wanted so you could maybe have it as like a kind of house type thing or just put an arrow there so you can see it anything like that you can add it in but i'm not going to bother and i'm just going to go straight over to the event graph here and i'm going to delete the begin overlap and event tick but on event begin play what we want to do is we want to make sure that we are using the event dispatcher we made previously in the game mode blueprint because that event dispatcher is going to be called when there's no enemies left so when we want to respawn the enemies which is why we're doing it in the enemy spawner so event begin play we're going to cast to the blueprints that event dispatcher was in like i said it was in the gamemode blueprint so for me that's going to be cast to third-person game mode just cast to whatever blueprint you have in so this might be in the enemy bp or anything along those lines and object is going to again be obviously get game mode if it is the game mode blueprint as third-person game mode what we're going to do is bind event 2 and then whatever you named your event dispatcher so i named it respawn enemy obviously put this as whatever you have it named for you it will always start with bind event 2 and then the name of your event dispatcher in my case respawn enemy and you can see we have this event here because we need to bind an event to this event dispatcher so what i'm going to do is drag out the event there and add a custom event and i'm going to name this one spawn enemy as that's what this event is going to do so that makes sense for me just another quick overview of what this event dispatcher is doing when we call that event dispatcher in the game mode blueprint i.e when there's no enemies left is going to call it and because we've binded this event now to us we've binded the spawn enemy event to that event dispatcher when the event dispatcher fires off we're also going to fire off this custom event here i hope that makes sense and i do have another video going over the event dispatcher a little bit more as well so i'll leave a link to that in the description down below if you want to learn a little bit more about that but essentially when the event dispatcher fires off this event will also fire off so it's just a nice way to communicate between blueprints and when we do fire off this event we want to spawn in the enemy and we don't want to just spawn in one we want to spawn in multiple and have it increasingly with each wave so out of this event i'm going to get a four loop like so just a normal for loop first index at zero last index is going to be how many enemies we want to spawn in so what i'm going to do is i'm going to add another variable here so hit the plus variable and i'm going to name this one enemy spawned or enemy spawned or anything along those lines and this is going to be an integer get that compile it and you can obviously set this to a deeper value if you want so the first amount of enemies that are going to spawn i'll set that to 2. we're going to put that in there get enemy spawned and then out of this we need to get an integer minus an integer minus one and connect that into the last index the reason i've got the minus one is because if enemies spawned is two the index will be two which is zero one two that's three different values so when this value is two it's gonna spawn in three so we just take off one it will be two perfectly so that way we know whatever this value is is how many enemies are gonna be spawned in so i hope that makes sense again essentially enemy spawned minus one in the last index of the for loop like so and then the loop body is how we want to spawn in the enemy so very simply all we can do is just get a spawn actor from class with the class being the enemy ai we made earlier so what it's going to do is for however many enemies we want to spawn it's going to spawn them in in the spawn transform i'm just going to do it where this blueprint is so that's going to be get actor transform for me like so that should work perfectly for what we want to do so what's going to do is just spawn in the enemy where this blueprint is and when we finish spawning in the enemy so completed we want to make sure that next time we spawn in more enemies so what i'm going to do is create another variable naming this enemy increment or spawn increment anything along those lines and i'm going to get that so get enemy increments out of this i'm then going to get an increment int so it's going to add one to that value like so and that will make more sense in a second because after this we're going to set enemy spawned the variable we already have which is connected up here and setting that what we're going to do is get enemy spawned plus an integer and we're going to add the enemy increment to it connecting that into the enemy spawned so what's going to happen is every time we spawn in the enemies the amount of enemies we spawn in next time will increase exponentially so essentially the enemy spawned plus the enemy increments will be the next enemy spawned so i'm also going to compile and set a default value for the increment i'm going to have it as 1 by default so by default enemy spawned is two and the enemy increment is one so the first time this is fired off it's going to spawn in two enemies then it'll increase the increment by one setting that to two and we have two enemies plus the two increments that'll be four so the next time it's fired off it will spawn in four enemies then we do this again that'll increase by one so be four plus three so the next time it spawns in it will spawn in seven and go on so on and so forth exponentially increasing each time so i hope that makes sense for you and you can obviously not increase this by one you can increase it by one two three you can do anything you want with this this is just the example i'm creating but again customize this to get it perfect for you and with a compile and save of that that is the code all done so it might be a bit more simple than you're expecting it to be essentially we're just going to kill the enemies once we've killed them we're going to spawn in more enemies exponentially increasing it by just adding a few integer values together so we can minimize this and get this working so what i'm going to do is have an enemy ai spawned in here automatically you can have one two three however many you want but just make sure you do have at least one in the world already and then just drag in the spawners where you want them so i want three spawners here and there maybe a fourth one down here as well so i hit play you can see we have this enemy here running around if i walk into it to kill it you can see the other four spawners have now fired off like so and they all spawned in two and then when it goes off again they're gonna spawn in four and they should spawn in seven next time let's see one two three four five six seven as you can see there however i have noticed only three spawners are spawning not a fourth one as well which is slightly strange let's delete that one and see what happens now those three are spawning so i put another one in here maybe let's see what happens only those three are spawning so that's a bit strange so we hit play again test it out now we've now got those three spawning in like so and one thing i'm also going to change which might also help fix this issue is on the spawn actor enemy ai here we can change the collision handling overrate from default to always spawn ignore collisions because if you get so many what might happen is they won't all spawn in because there's too many in one place however if we always spawn them they will eventually spread out when they start moving which will work perfectly so let's also test this out once again and as they keep increasing they should keep on spawning as you see all four spawning now so that did resolve that issue so i think that'll be for this video as we've done everything we want to do we've set it up so what we've got is an enemy wave or horde system so when we kill all the enemies in the level the next wave will spawn in with the amount increasing exponentially each time as you can see here and you can obviously change these values to get them perfect for use they're not all this easy to kill or anything along those lines and i think the reason they're bouncing up in the air there is just because of how the positioning i've got them in they're kind of in the floor a little bit so to raise that up they're not all going to fire off in the air like so what that one did that is very strange so we again it's just gonna be messing about with the collision so try to adjust location but always spawn let's have a look at that one and as you can see that's a lot better so again it's just messing about the collision to get it working a lot better and perfectly for you but again this does work perfectly you just might need a few tweaks here and there to get it working better for you and how you want it to be and obviously if you want some help with those specific details of tweaking it customizing it for you let me know in the comments down below but thanks so much for watching i hope you enjoyed and i hope you found it helpful and if you did make sure to like subscribe down below so thanks for watching and i'll see you in the next one [Music] you
Info
Channel: Matt Aspland
Views: 37,702
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, 3d modelling, blender, unity, games design, graphic designer, ue5, unreal engine 5, enemy, enemies, wave, waves, hoarde, hoard, system, horde, hord, hoards, based, game, spawn, spawning, spawner, rounds, increasing, each, time, multiple, more, kill, killed, chase, player, the, ai, area, all, ue4 wave, enemy wave, wave system, horde mode, wave based
Id: gP2ozW0dLZ0
Channel Id: undefined
Length: 16min 56sec (1016 seconds)
Published: Mon Jun 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.