Unreal Engine 4 Tutorial : Saving multiple locations/Items

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay hello guys welcome to another Emil in June fall tutorial I'm gonna start today first of all by actually apologizing I'm sure that Mike for not been around much recently had surgery and it's been pretty uncomfortable to do anything but lay in bed so I mean even seeing it my computer's been pretty painful but recovering still back on track back on the mend and coming at you with another tutorial I recently received an email from one of my viewers asking me a pretty specific question so I'm gonna answer that with a fairly broad tutorial that hopefully answers his question now what we're gonna take a look at is saving the location data of multiple objects of the same class so still rather specific but as you can see I've got this cute with balls on top and these are all class one these are all the same class if I bring this out into the world that's just another one you know this is the exact same class just replicated over and over again in the world now what I'm gonna demonstrate what happens basically first of all so you can see here we've got all the objects now if I move some of these just spray this thing around let's just move these into a random pattern and if I press the letter G it says on the top there savegame complete now if I exit hit play again okay so much all my saved dates is gone if I press K it now moves everything back to where it was my present company included moves the player back to where the player was where the play was looking and you know it puts everything back quite well so I mean we could move that again and overwrite the save game so let's just push this one over here in fact we could even shoot it into the air and try and save it while it's in the air that's kind of cool let's just see if we can get one of these things up there come on easing now busy know about you you're gonna you know cooperate for us oh no wait a minute wait a minute whatever it was kind of moving that's um but now basically look if I run over here and press K it's gonna say where everything was and it saves it it's a safe system that's all we're looking up so how do I do that well what I've got is it's actually it's not complicated but it's not short either so I've actually got print screens on my other screen so forgive me if I pause for a minute and just kind of load up what I'm going over that just took just some notes basically so let's go ahead and delete all this and we'll start from scratch so let's start ooh as if you if you've just opened up a nice first person template you're not gonna have any of this yep I'm gonna have this and inside your first blossom blueprint you're not gonna have any of this so that's what we're making today the only thing that's different about mine let's go ahead and play those I don't know oops I didn't want to leave that one elephant was different about mine is I have this hell variable here and basically it just allows me to make that you have the little ball that you shoot makes that into like a machine gun kind of thing that's the only difference makes no difference to the safe system and if blabbering on a top for three minutes and I'm not showing you anything so let's go ahead and take a look at what we can actually do to get this system working so the first thing you're going to need is a class now you're you're almost certainly going to have a class that you want to save otherwise why would you be watching this so I'm going to go ahead and quickly make one if that's I'm going to make one an easier way let's grab a cube here turn into a blueprint and call this plus one and inside that blueprint let's just add a mesh not a skeletal one what am i doing a static mesh just to make it stand out from all the other cubes that are on the map so let's go ahead and stick a ball on the table let's duplicate that holistic two balls on there I can't do that whatever I'm wasting time so it consists of a cube and a ball so that's my class that might be anything you've got multiple ones I've run them up let's say you allow the player to move bins around the map or something you know this is your bin class right here so we can go ahead and compile that save that that's that now the only other thing that we're going to need is a save game so we're going to go to right-click or down here a new blueprint class and it's going to be of type safe so save game here like ten and give it a name the save game something other than save game it needs to have a prefix or suffix it can't just be saved game that is very important it needs to be the save game say game one say game Joel save game computer anything right just really gotta ever mention that so go ahead and save that now in here we need to do pretty important things so we need three variables this will just okay if you want to expand this to your game let's say you want to save the position of two classes three classes twenty classes take notes of the procedure that's going on here and replicate it right the only thing that you won't replicate is to play a location because you've only got one player in the game right oh so I'm assuming that this is a single player game anyway transform player transform save so this is gonna save the transform of the play and make sure we take that this variable over here is visible so compile that add another variable again this one's gonna be a transform however this is going to be an array this is going to be class one location array save so again we're naming variables things that make sense to us and these will all make sense a bit later on I'm gonna another variable now this one's gonna be quite specific this is where you specify what you're saving so this is going to be plus one it's an object reference there to class one again it's an array so this is class 1 + array save so we're saving the the transform and the opti the close having the transform and the instance object in two separate arrays because you can't store the same date you can't store more than one data type in any one given array so we need two arrays and what we're basically gonna do is have the index on these arrays line up so mmm how to explain this is quite complicated actually okay so you imagine you've got two lists right you've got two pieces of paper on front of you and you've got two lists on there let's bring the pain sir stop the tutorial on that wheel quick and just demonstrate what we're actually doing is good to understand this so we've got two lists right now let's say I add an oval this list but I want to store not just an oval but I want to store its location so I'll put its location in this list now what I'm going to do is make sure that one here lines up with one here and two here and three here line up with two and three over here so when I add more than one oval let's say I've got three ovals on my map yeah I'm going to start the location data for them so then over here I have a little machine this machine is a list processor or whatever and I say okay I want the location of number three yeah I want the location and the object of number three so we'll say okay this array I want number three so I'll bring out on over but it'll also call to this array and bring on the corresponding object so now inside this machine here I have oval number three and I have its location that was stored in the second list there I hope that kind of clarified things please I should you know let me know in the comments if that was helpful or not if it was not I will never open paint again and show you my awful drawing skills anyway got those two arrays and the one transform set up let's save that let's head on back out so our firstpersoncharacter and let's go ahead and set this up so we want a savegame button let's go ahead and use the letter g okay so when we press G what are we doing the first thing we're going to do is create a save game object and now this class is going to be the one that created earlier notice I said not to save as save game that's because I'm real already Unreal Engine creates one for you and we need a different name there so we need the save game so yours might be save game prefix or suffix whatever you put there let's go ahead and grab that and then we're going to need to promote this to a variable so we're going to set the variable we're going to name this save game sub class right now from here we're going to cast to the save game and now this is where I've got a kind of tab back a fourth term and print screens right okay okay we're going to set that we're going to save the players location before we start saving the location of the objects so we're going to make a transform another transform consists of a location a rotation and a scale and the way we're going to set those is by getting the location we're gonna get a Couture location now we're gonna need the target there of ourselves so we're getting our current location we're going to get control rotation so which way are we looking and we're going to get back to scale 3d so how big lb how big is our x y&z axis those are all gonna set to be set to one but it might vary if your player is like Mario and scales up and you want to save his current state then his scale will obviously be a bigger so we're gonna make that transform now what we're gonna do is as the savegame we're going to set and now you can see down here with these three options plus one array save we don't wanna do anything in there yeah class 1 erase application basically so up we want the player transform save so we're going to set that transform to the transform we've just made so now over on that save game subclass here I'm gonna press G it's going to say okay I need a save game and I'm gonna open that save game and I'm going to set this variable here to this variable coming out of here which consists of my actor location my control rotation and my actor scale 3d now okay great we've said to play a location kind of now let's go ahead and work with a raise I love a raise recently I absolutely love arrays but let's go ahead and let's play the race so we're going to get all actors of class and the class is going to be class 1 so this is where your game is saying ok every class in the game every class in the game that is class 1 raise your hands let me find you and it'll put you all and said this big list here so okay cool we've got a now nice big list of all of the class ones in the game and for each of those we're going to do certain things so what do we want to do well this is very time back and forth when I go from here to a sequence of two things we're going to do two things for each item so let's say there's 10 we're going to do two things 10 times right getting a bit complicated I know but bear with me now if you scroll all the way back over here to the savegame class we're going to get two things from here we're going to get the location array save put that up there for now and as the savegame again we're going to get the class 1 array safe so the two arrays that's what we're now working with me to get those basically and now out of your pins here actually could drag it off the array rather and just press add and again if this array and just press that again okay so what do we want to do now out of the array element so okay how does I need I feel the need to explain what's going on I don't think just showing you how to do something is any good I always feel the need to stop and explain what I'm actually doing I hope that helps so the array element so it's called all of the actors in the gate all of class one so let's say we're working with Club were working with the first class one so we've got foot we've got class one underscore one here what we want to do if class one has got one well I want to get his specific actor location I also want to get his gift rotation notice that we're not using the control vector for this we're actually using the actor rotation and that's because as an actor as opposed to a player he doesn't actually have a controller he is simply a enact is just a thing so we can just get his actor rotation this way you cannot use this over here it just doesn't work you need to get the control rotation because you're getting the way that the control is looking not just the way the actors looking they are two separate things just by don't mind and finally off this array element here we need to get actors scale 3d an hour of those we're going to make a transform plug all these little things in and I'm going to plug that into there okay so let's quickly take a look what we've done for class one underscore one we're getting its location rotation and scale making a transform of it and adding it to the array but then we're also going to add it to the array to a new array the new array inside the things saved so we're breaking an array down here let's say this list here has this list that we've got 12 classes so for each one so okay class warm what am i doing I'm first of all getting your location setting it up in a separate array and I'm also adding you to the new array and I'm gonna do this for each just waits a for each loop so it'll only do this 12 times if there's 12 glasses they'll do it 20 times if there's 20 classes so that's basically not it for the sabian okay so we've we've added those to the array right now when now okay so we've completed that we've added those to the array now we need to actually save the game so now that we've done that we're gonna go on down here to go to just save game exists and this is where we need a new variable it's gonna be a string we're gonna name this save game string now make sure you compile that and set the value in here and that's going to be save game one basically when you go to your player content folder and you got two users Joel saves this is what the fault this is what the file there will be called it will be called save game one if you want to name your file save board it can be anything you could put lucozade glass bowl you know you put whatever you want in there it could be anything but just drag that out here basically and plug that into the slot name so if we're checking does this save there's the save with this name already exists and actually do we even need to do that do I use our data gosh you even use that data we don't need to do that just yet but do keep the variable we will be using that it's going down here I'm just save game to slot and we're saving it to this slot and the save game object here is our save as' of the class so I'll hook those up so we're saving all of the data inside this saver subclass to the slot with this string so we're going to put it all in there as a nice little text document and out here it's nice to just do a branch with to print strings so did it to do and if it's false say failed and if it's true save complete that's just a little something to let the player know that they've um they've saved the game properly and everything's looking good so put that one in green put that one in in red so save completes they failed that's fine now that's our save system there so let's just go ahead and put a comment around that save the game compile it hop into the game and right we actually need some of these classes in the game to say so let's go ahead and move some of my class ones around those hit play and if I press G it's gonna save them save complete see that there that's fine if they're all saving just fine and actually if I head on into my documents and find where I've put this save game real projects saving multiple items saved save games you see video but there we have save game 1 dot save now if I'd have named this something else like if I'd have named it save one that would say save one that's out there just to prove there that the save file is there now I can go ahead and remove that and delete if we delete that so you're starting out with no save game it still works it still creates the save file when you pressed you save completely still they're down so it's green that's all fine okay cool so we've saved the game to that text document now what well it's no good unless we load it back in basically so what I'm going to do is hop on back over to my first person character here and we're now going to save the game so when I press the letter K that's gonna be my import my action we're going to check now does save game exists now this is where we're going to use it so we get the same same string there does the save game save game one dos app exists and we're just going to do a quick here we're going to print a string if it doesn't I'm just gonna say unable to load say save does not exist so if it doesn't exist it's gonna print that and if it does then we're gonna go on to do something we're gonna go on to load game from slot and I mean though assume that this block here is pretty explanatory what it does it checks it gets the slot name save warm and then it basically loads from it so what do we need to do now well we need to set the return value of here need to set that to that so what it said is okay that savegame slot that we saved earlier with those transforms in the array in it I'm gonna now set this to match that so this will be this will be set all of those variables we brought out of that text file or the dot save file and brought into into the engine here into this class and then we're now going to Kuster to the save game and now this is where our loading process really kinda kicks off so we need is another sequence and we're going to do two things the first thing we're going to do is load the player so I need to get the players transform and I need to set back to a location and I'm only moving myself so I can actually to break this first of all so we have access to all the location rotation on scales I'm going to set the actor location or myself I'm going to get my controller actually and I'm going to set control rotation so I'm going to set the rotation of the controller hooking that into the rotation there and I'm also going to set scale 3d so I get to scale 3d and hook that up into my scale so the first thing that's gonna do when we're loading is break the transform so it's got the save data it's got the saved a to transform I'm gonna break it down into its location rotation and scale we're going to set the players location we're gonna get the controller then we're going to set the rotation of the controller and we're also going to get the actors scale 3d and set our our scale to that basically now the second thing we need to do is work with those array so we need to do another for each leap okay for each loop there we go and the array from this is going to be mmm okay we only need to get it the array from this way let's get the class array and we also need to get the transform array okay so for each item on here oh how do I do this array index forget yeah okay to do that should you ever quick think about this here yeah that's fine that's fine okay so basically what we're doing is we've got the say good in class it's full of that array remember those twelve classes that we saved earlier now for each of those classes we're saying okay so I'm getting it starts obviously with zero then one so for item zero on that list class one so okay which clues item zero this lists the people right whose item zero I asked I said okay so your item zero so remember how on the paint demonstration earlier I said that it would correspond the number so in aligning the numbers up well this link here basically shows us that we're lining those numbers up so you've got you've got number one on one array is equal to number one on another array I'm not I really am struggling to kind of explain what I'm trying to do here but I hope it all makes sense anyway let's go ahead and get through this a bit set actor location that rotation that's not the one I mean to set location so what I'm doing here is I'm setting the actors location the actors rotation and also in case you can't guess yeah the actor scale 3d so for each to do hook these up so for each of these items I'm going to break this right so I have an array of transforms it's really hard because everything's kind of packed up and packed inside something else I've got these these bits of data here which each consists of three pieces three individual integers or floats even so I've got three floats condensed into a data type three data types condensed into a further data type and that data type held in an array which holds multiple multiples of them so you know if we're really packing things down here to save this it's a location one Hawkins here the rotation we're gonna hook into here and scale will hook in there and hook that up and that's about it okay so let's just quickly explain what's happening here so we're gonna Kuster the savegame I'm gonna do two things the first thing I'm gonna do is open that same VM up get the players transform save we're gonna break you down into car components rotation location rotation scale we're going to set the player to those location rotation and scale so set the player to where he was then we're going to open the arrays up so for each item in the array let's say there's 12 in the array for each one so 12 times this is gonna run so for number one we're gonna get number ones transform we're going to break it down and set number one to number ones transform number two we're gonna break it down set number two to number twos transform and then we're done so I'll have completed on that we can I believe just leave a little note saying loaded but uh Jalili you'll know it's loaded I guess so let's just go ahead and fire this up and hopefully this works so let's go ahead and just move these things around a bit and press the letter G save complete there let's say well do actually let's go ahead and delete them all and set them up nice and organized on the map let's find those classes so let's make it a nice little nice little section of them so no chaos nice and organized let's go ahead and shoot these down now move them around so you know what mess them all up they're all messed up now all in different places all over them up now let's go ahead and save the game right now if I load that game up again everything reset how boring now proposed to LEDs okay everything's all messed up again I went back to facing the way I was facing everything's all spread out all over the map again and if I'm not mistaken there should even be one of them down there there it is so there you go so we couldn't even we can use that same save game we can move them again just I should have made these things lighter or something go ahead and move another one into that corner let's put three in the corner and then let's press the you'll notice that these little ones here these little cubes don't save the location if I wanted to save the location of these cubes that need to turn each of them into a class and then go through the whole process again of first of all storing them as an array within the savegame class and then loading them again so let's just press G anyway exit the game and then press K you'll see that the little ones didn't move but all the big ones did move into the corner so there's now two over here it look it doesn't look the same simply because these little ones didn't move but I promise you that was the same I'm sure you can see that so that's really it for this tutorial so we're taking a look at saving and loading you kind of cost load while in the same saved game component put them back again I can keep pressing K basically just loading them over and over again I'm just setting the location of them Solander so yeah that's it for that tutorial guys I hope that's been helpful I hope that's been especially helpful to the guy that requested this you can reach me via email and request specific tutorials tutorials specific to your needs are quite hard to do because if I went around helping everybody with their individual problems I wouldn't actually get any broad tutorials done but you can always request a tutorial and if I can find a way to make it broad and help a lot of people I'll I'll tell you into a tutorial certainly otherwise I may offer some kind of one-on-one help but um yeah so I guess that's me soon and back back on the horse probably gonna continue with those AI tutorials but I wanted to get this out there to help the guy that requested it I hope this has been helpful if it hasn't sorry I guess if it has fantastic do not forget to give the video a great big thumbs up comment on it and most importantly please do subscribe to channel a lot of people says it helps it really does help so yeah absolutely appreciate you view in the skies I hope this has been a big help as always I'll see you in the next video
Info
Channel: Totally Unreal
Views: 21,614
Rating: undefined out of 5
Keywords: Unreal Engine (Video Game Engine Family), Game Engine (Software Genre), Unreal (Video Game), Shooter Game (Media Genre), Tutorial (Media Genre), Level, Server, Help, Software (album), zombie game, zombie, unreal engine 4, uhe4, ue4, Video Game (Industry), Album, Tips, Metin2, Logging Time, New, Need, Industry (Organization Sector), Tricks, Runescape, Your, Please
Id: MLqypbTyZG8
Channel Id: undefined
Length: 26min 37sec (1597 seconds)
Published: Thu Aug 20 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.