UE5 Player Stats Component Guide - Part 4: Characters and Clean up

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to my stat component Series in this video I'm going to show you how you can set up your stats to uh basically scale off different type of characters uh so what we're going to be using is a data asset and then depending on the data asset we will scale our stats per level based upon whatever set in there so I'm going to use three examples where we're going to have like very standard um classes such as like a warrior Rogue and Mage and then we'll have basically some that is strength based agility based intelligence based and then when they level up they will gain those appropriate stats afterwards I'm going to go into a lot of just reorganization uh creating macros and and functions to clean up a lot of what we have to make it more concise and just cleaner uh so you'll be able to see that process we're also going to just add notes to things as well as like descriptions um going to be going over that a little because I think that's really important to go over uh it's not really the purpose of this um series so you don't really have to watch that portion however um I think it's really useful for everyone so I think you'd enjoy it so let's get into it okay so let's get starting our data assets so what we're going to do if you haven't created data assets before don't worry I'll just kind of go over briefly on what they do how to structure them they're pretty simple so with this what what I have in mind is I want to create a data assets that's basically going to contain the amount of stats I'm going to level up uh you can also include other things into it like other class data you may want to store um I'm really only doing stats I'm not going to go into like other things but maybe if you wanted to throw in like what the character model is going to be or um like a character's name so like obviously their name's not going to be Mage you'll have I don't know well whatever um could be Harry Potter I don't know you choose so with that I'm going to just have some simple stuff I can store there but really you can do a lot more um now let's go into here now one thing is um generally what I do is when I'm looking for something I actually just type it most of the time it's just saves me life my life um what we want to do is we want to create a data asset uh however uh we need to First create a primary data asset so this we'll create data assets based upon um the primary so kind of think of it as like there's a parent and then there's children so what we want to do is we'll type in Blueprint class we'll type in data asset and then from primary data asset we'll hit select we're going to call this da for data asset underscore and we'll just call this [Music] care for character and then we'll just do um info maybe another underscore just to give it a nice little space and actually let's give it a nice separate folder for we'll do character info and we'll throw that in there and then from here let's open this up so from here you do have a event graph so technically speaking you could create custom functions for your data asset so that if you end up using it you can end up calling it later uh you may not understand that fully yet but we'll get there but most of the time what you want to do is you need to set up the framework of what you want to store so usually you're just going to go into the variables and we'll do that so for example if we want the data asset to have a name so we could go um uh class name let's change this to a string We'll add something else we'll just do with like character name leave it as a string and then from here we want to have the stats so this is going to be uh level up stats or sorry attributes we renamed it so upon leveling up we want to be able to have what stats are going to level up with whatever amounts uh you could use this for the strength agility and intelligence uh we're not going to be using it for XP because we got a data table for that you could also do this type of information in data table as well uh however I wanted to do a data asset just to kind of showcase the usage and I do like to use them as well and it doesn't require you to search through a data table so it can save you some time based upon your usages uh you just got to know about how to do it so what we need to do is we want to be able to store the the stats but we need to know what type of variable it needs so if you actually went to our attribute if you don't remember I mean I remember but just to Showcase what it was is it's a map of attributes and float you can go into here as well as just changing all of them or you can do the simple way of just doing contrl C and then contrl V and you can copy it there so that can actually save yourself some time as well it's really small if you just want to type it out click it that's fine too anyways let's change the name level up attributes and we'll hit compile so this is really all we need to do I'm not going to go into custom functions but um I'll maybe just demonstrate that at the end if I feel like it so this sets up the basic function so every data asset that comes from character info will have a class name character name and level up attributes um if we were to open this up we show all here let's actually just default all these to zero and then let's get rid of the ones that we don't want here so we have strength agility intelligence those are the only ones we want here saving that and then you can actually close that out we're not going to need to reopen that going back over here let's create a new folder call this data underscore assets and from here this is where you can type in data um data and you can just get data asset if you want to find it it's under miscellaneous data asset cck here from here we want to Now search for the primary that we created uh so you can look for other data assets that are available here uh for me it's the da character info hit select we'll do the same nameing naming convention da and we'll call this Warrior for our first class and then let's controll D to create two copies and we'll name this one daore Mage and then this one we'll do underscore Rogue and with that we have three classes if we open one up so this is our Mage we'll notice that we have the class Name the character name and then level up attributes I put these mainly as just a demonstrated demonstration of what you can include but really we're only going to be using level up attributes because like I said we're focusing on stats uh class name obviously this is going to be a mage for whatever name you want you could put anything um um I'll put opa and then for level up attributes now this is what we're going to be using so every time that we level up instead of using a data table we'll say we're going to be leveling up using these stats so I'm going to have all of my classes level up and gain a total of let's say six stats per level so every time they level up they'll distribute six stats accordingly uh so for this let's just go with uh four one and one so the Mage is just very heavy intelligence and if we open up our Rogue we'll notice we have the same thing so we could do the same thing we'll just do that Rogue and um I don't I don't even know I I should have thought through the character names a bit more um we'll just call this Misty and since we're Distributing six let's go two three what was that five and then one and then we can close those let's open up our Warrior and for this let's just do the opposite where it's just 411 we'll name Warrior and we'll call this guy brick actually shrink that because okay so with that we created the three data assets and now all we need to do is we have to be able to use the data assets So within our Stat system we're going to add another variable here uh let's name this um we'll just do care info and then you can actually search for your data asset so daare input we're going to use object and then from here hit compile and you can actually hit the select obviously for your Stat system you're going to want this to have no default value but what we can do is in the character if we were to open them up now if we go to our system we see care info is shown here and you can select so for there's multiple different ways that you can set the data asset however um if you have different characters that are like child blueprints of the parent you'd be able to set all of these data assets individually so for example if I were to create a child and we'll name this BP Mage if we were to open up the Mage we can then set the data asset to Mage and just like that you'd be able to do that for all your characters now this does depend on how your character system set up maybe you want to not do that and let's just say under your construction script you wanted to um let's grab this uh data oh what's it called sorry care info get um do validated get so from here let's say you wanted to see what you have available in this data asset and then actually no scratch that scratch that uh I may edit that out so let's say you wanted to do let's grab that and do set a info and then upon the be beginning of the game you would set this to something so whether it is Mage or whatever you would have to get a stored variable to plug that in so maybe upon creation you'd be able to set this that asset uh there's there's lots of different ways it really depends on how you create your characters um I am going to do it very very simple where I'm actually just going to set it within the character because let's say I created um a mage character um not an allinone where you can use it for every character and then you'd be able to just set it accordingly um actually let's just use Warrior I don't know why we we can be brick today okay so that's for setting the data asset now the next thing is upon leveling up we want to make sure that we are using those stats as of right now if we went to our level up we're showing that we have this really really long function if I zoom out for here that's covering everything and that's one of the things I wanted to fix is because honestly it's it's just too long and uh it could be a lot cleaner so from the start we don't need our stats list to have strength agility intelligence anymore so this data table that we have we can eliminate strength agility intelligence because we're now going to be using um here if we were to grab off uh attributes uh find and we can actually grab our string of course I'm not going to do it like this we'll create a function to make this nice and neat that we can reproduce like we did with this attribute value uh so I'll be able to go through that but first we want to clean up this a little because we don't need this to be showing all of these stats so actually I'm going to delete this and then we're going to delete all of these add attributes because we're going to be doing it differently now and from here I guess we could just plug in in the mean me time just in case we need to edit this list so let's go back to our Stat system let's go back to our stats list and let's actually just delete delete delete delete and now that we have in fact deleted it the next thing that we need to do is we should rename it because this no longer actually applies to Stats it's literally just a table used for our XP because if we went back into our data table you'll notice all we have is level and Max XP so we're just using it for leveling so let's go into here we'll rename this instead of stats list let's just name this XP list and we wait for that all right and from here we'll be able to let's actually [Music] create a I'm going to create a folder just for strs because part of this is to reorganize and show you how to go about doing that we're going to put strs over here which also means we're going to see some saving we'll move that as well though um I actually have a better solution for stats multiplier so we're going to actually be doing that as well and then we'll do it an enums folder we'll plug that in as well all right okay so we fixed that so now this will only show the one which is all that we really need it for um maybe I can condense this a little okay and we'll bring that back over here okay so from here what we want to do is we want to be able to find the level up attributes so this is what contains all of the attributes that we're going to gain upon leveling up that we set within the data asset so if I was to open that back up let's just have that on the side just in case we'll notice that when we level up we're going to gain four strength one agility and one intelligence so we need to be able to find that and then we need to add that to our current value uh so from there we would need to do I wonder if we could do this what's add attribute value yeah you can okay cool and then from here you would have to then select okay now we need to do strength of course doing this three times is just going to give us a repeat of what we just did so let's actually we're going to condense this to a macro and we're going to call this level up attribute so now we have this little tiny thing and it doesn't do anything yet but if you open it up you'll notice that we have all of this and it still exists and let me move this aside a little and for macros you actually can just drag and pull these in and it'll add the nodes just like so let me straighten it out and we'll plug that in and what we'll do is we're going to be using the exact same attribute that we're gaining so since we copy and pasted the same exact attribute you can actually just plug this in and you can plug that in and like that we have a nice little macro that we can add attributes uh for all three of our stats we just have to set it a little bit so from here um oh that's weird usually there's like a drop- down list wait hold on maybe the attributes oh yeah see okay there it is okay that was weird not sure why it was doing that um that's fine you just have to manually do it I guess instead of uh any who if you manually add it then it gives you the list where you can feed an input because now if we were to like drag off oh you can't do that in the same thing but like here well we have the level up attribute now we end up showing that hey we have level up and we could just do strength agility and intelligence so we could do that and then after we have the update stats and another thing I actually want to do is to condense this even further is I'm actually going to highlight all of this and I'm going going to collapse this to a function and we'll name this level up all or let me level all attributes and if we move that over here and move that over here by opening this up let me clean this up a lot because that's weird okay so now we have macros that help us level up the attribute that we so choose and then we have a function that will just level up all of the attributes um from the start and then it goes into updating all the stats which we have over here which it's updating strength agility and intelligence and then by updating updating the strength we do all of this blah blah blah and that's actually something that I want to clean up as well but let's uh get into that after I have actually fixed all of this with the stats so I guess the important thing is we want to check to make sure that what we just created is actually working so let's for starters go into our character because one thing that I also noticed is that the defaults um hold on we should change these to zero and I'll get into how we can set the defaults um or you can set them yourself if you want that's completely up to you but anyways we'll go into that in a bit and then let's go into here and let's just make sure that we set the defaults um we'll leave that at one we'll do z z zero and do we have a debug for gaining a level I think we do it may just be in here maybe oh this is so disgusting I forgot that we did this um we made a UI and we shouldn't need that anymore let me copy that and paste hold on I'm reorganizing because I didn't realize how disgusting this looked right now and then we'll do debug key 3 and then we'll just do print add XP okay that should be better okay okay let's go into here we have one that opens up we'll notice that we have like no stats obviously that's not ideal except for the armor for some reason uh oh that's because it's the only thing that doesn't scale right right right anyways we add XP we should gain a level now we did and we'll notice that our strength went up by four agility went up by one intelligence went up by one so we do know that that is in fact the stats that we wanted because we have 41 one everything is scaling as intentional and then the rest of this just scales based upon what these three stats are so perfect we know that's working great going back into here now that we know that works what we also want to do is this update stats function we actually want to set our starting stats so let's go into let's see I wonder if our level up will work let's delete that let's let's try to see first press one yeah so we have our beginning stats and I think that's because our current level is one yeah cuz level one and then we'll pull M XP set the max XP based upon that row and in our data we were to open up our level Max XP is 100 which means it's setting our Max XP which is great and then we are also leveling up all of the attributes and like that we're able to set all of our starting attributes however one thing is that I wonder should I do a save and load so you can see the stats you know what yeah let's do that okay so we don't need to update all stats because our level up actually has it um over this sorry so many functions update all stats is at the very end so let's go back to our event graph and I'm going to do a new function which is going to check a save game object and we'll go through that so that way when you start up a game you could just reload your current stats so we'll go new function we'll do um starting attributes from here we'll do does save game exist I haven't created the object yet we'll get there and we'll name this just let's just do I don't know slot one and we'll do branch and from here if there a save game doesn't exist we'll just set the stats to level up because we're going to be level one and that's the default and then we're just going to gain a level so that's exactly what we currently have this is always going to turn false because right now we have no way to save and then what we'd want to do is do let's see load game from slot and we'll do stats and then now we have to create our object because we don't have a save game object yet yet so let's go back over here um do I have a system now we'll create a new blueprint save game and then from here just like we did with the uh data asset where we just have a attribute we're going to do the same thing for our save game so we'll go save game attributes or sorry save game slot one also I realize I put stats instead of slot one always make sure the save game slot and stuff is all the same uh depending on what you want to open so I'm going to open this up I'm going to do the same thing I'm just going to copy this and I'mma paste by default yeah we should leave it exactly the same so from here if we in fact did have a save game slot uh there there's two things that you could do here for one you can use a um blueprint interface I'm just going to use casting um because for my save game I think it's it's fine uh but you could do blueprint interfaces if you wanted to avoid casting but we'll do cast to SG G slot one we'll get the attributes and all we would do is set our current attributes to here and then from there trying to think we would need to update all of our stats so I think we' have to do update all stats okay so let's go ahead and do another debug let's do debug key4 and then this is we're going to save game to slot um oh wait let's get I think I need to do sorry not save game to slot we need to create a save game because we don't have one yet create save game object we'll do SG slot and then from here we're going to set attributes and we're going to plug that in so what we're doing is uh because we don't have a slot yet we are creating one and then we are taking the variable inside the save game and we're setting it to whatever our current stats are so whenever we save we'll pass along our current stats and then we can load it up in the next game so that's all that I'm doing right now and then from here we're going to save game to slot so we're going to save here to here so the object we created is going to be saved let's just clean that up a little and then we know slot one also you can you can also just promote this to a variable and use that as well so you could just have the SG name and then I can actually go back to the other functions I know I'm jumping around a lot but that's because I'm doing a bit so from here we can just plug this in and plug that in that way it's just consistent so no matter what no typo errors all right and then just to let us know that we actually in fact pressed the button let's just do print and do save attributes so what I want to do to test this is we're going to gain some levels and then we're going to save it so from level one we have our basics stats awesome that's perfect let's gain some stats all right I'm level five now we notice I have all my stats we close that and on the top left I'm going to hit four we saved them let's exit out of the game open that up all right it looks like our stats did not update so it looks like something happened where it's saved to slot one but our starting attribute function did not in fact work so let's see um load game from slot I wonder if it's because I didn't create [Music] let's let's try this create well no I don't think I should need to maybe I should create save game object does save game exist this feels wrong no this feels wrong that's not the solution if save game exists we're going to load a save game from slot Which slot one slot one and then from here we set the attributes um maybe I should change it to a different let's go into slot one let's change the name to like slot attributes to not confuse myself and we'll delete oh wait we don't need to delete anything um okay try that again hit one we have all of that gained XP we saved it so I'm level four right now in the save slot we go into here press one nothing is loading okay let's see starting attributes we go to the event graph oh okay that's why there we go okay yep I'm just uh super smart left off the event but we notice that we're level four we have all our stats we're doing great uh if I close this out let's gain some XP level six now I hit save we go in here press one and we're still level six so just like that we have all of our stats they are saving perfect so we do have all of that working now let's uh let's do some cleaning up so I want to actually clean up a lot of this and that's with all of the stats so let's um delete that I want to clean up let's let's see all of this really and I think there's some macros that I helped create um but I I did some modifications to them so with that let's let's do this let's collapse this to a macro we'll name this scale stats let's open that up from here what we're going to want to do is very similar towards the other level up macro where we have over here where we just plug in we're going to be doing the same thing uh we're going to create this we'll name this um select oh oh attribute okay and from here you'll notice that we no longer have our stats so I kind of broke everything else that was actually intentional because I want to change this so instead of using um the stat multiplier we are actually going to delete that you can delete that all together yes we don't need this anymore we're going to go into strs and we're going to delete it fully intentional I don't want it anymore it closed out that that's fine and the solution I'm actually going to use is that instead I am going to use a copy of this variable so so I'm going to contrl C contrl + V you can also just do contrl D whatever you want to do and from here we're just going to do this as multiplier stats all right once again suffering from unrendered crashes but nonetheless uh what I want to do is we're going to control D this again and we'll do multiplier stats now our multiplier should be the same for everyone I mean everyone scales exactly the same so this is just where you would set the scaling uh so like we did before uh we'll just set it to um uh we don't need health and we don't need Mana because we're not scaling that and then we're also not scaling armor so we'll be able to do that we'll do 50 25 and then we'll do 0.1 and then attack we'll just do like two all right and then just like our stats we'll be able to control what stats that we're going to multiply with so we'll go into here we want to find the stat that we're going to scale uh so let me actually let's let's move this down these two are always going to be the same so we'll have a select stat instead of select attribute select stat change this to stat uh let me actually change the order drag it over there okay and we'll plug that in we'll plug that in looking good um oh maybe I'd do a pin right here and just bam okay little cleaner a little cleaner and then we have this multiply and we'll just plug it in here and plug it in here so we'll be able to scale them accordingly drag that back so like that we'll be able to scale our stats and we can use it for all of them so going back over here uh now you just select so from up when we're updating strength we're going to update our Max Health with strength and then we'll be able to do the same thing for attack so we'll be able to do this based on attack and we'll do agility and delete so we'll be able to do that and then intelligence is going to be the same thing with Mana and Mana region so we do here and let's go Max Mana intelligence Mana region intelligence I'm going to zoom out a little because I'm going to condense all of this and we'll do here and more zooming you probably can't see but that's fine um you tell this is a bundle of joy to do all right I could have just deleted it and redid it so we end up having the update all stats where you can scale our stats that's looking a lot cleaner uh so we were able to condense all of this uh let me see and I think one thing we could do is I have an idea where we can utilize this to update specific stats if we ever need to so let's collapse this to um let's collapse to a function we'll name this update stats we actually don't need it here so we'll delete that from here what I have in plan is that we'll be able to choose what stat we want to update so let's say you added somebody something um you can pass along what stat has been updated so let's say you specifically only um added intelligence you'll be able to call this function and then just add the intelligence um and then we'll also just include an option where we can update all of them like we are doing here uh so by doing that I'm going to create oh autosave come on now I should really reduce the timer on that I swear okay anyways we go into here um we're going to name this update all stats we'll name this Bo a boine and then from here we're just going to do a branch and then if it's true we'll just update all our stats so like in the beginning of the game we'll update all our stats as intended um the next thing we'll do is I'm going to do a switch on attributes and then we'll do another where it'll be select attribute attribute and we'll plug that in and then upon here we can just do if it equals to strength do that and if it equals to agility do that and if it into equals there and we we can close like that o what's going on over here um oh I don't even know why that's there I don't even think that's what I put there um that should be starting attributes here and then from here delete that we'll do update stats actually yeah that should be correct let me Zoom back in and then we'll just select the update all stats and then if you wanted to update a specific one you can actually pass along like which whichever one you want to uh later on I think this will be pretty useful or it may be useful to one of you if you wanted to uh like have items and you pass along what attribute they have like so if they have intelligence you pass along that what they're updating whatever it is uh compile looks like we're still failing um okay and we'll do that again and I think that kind of condenses a lot moving this over that moved to slightly and we'll move this over and we'll move that over okay so we were able to condense this hugely oh that's off just by a little and it's bothering me so sorry um to focus on the sizing but now if we take a look at a long scale look how short it now looks it's actually a lot better um let's see is there anything else we can probably condense maybe we can condense this no no that's that's fine that's actually I think going far and I don't think it's necessary um yeah okay level up okay so with that I think we did uh a lot of modifications we learned how to add different characters you can just create different type of data assets I also showed you how to do data assets uh so I hope you learned from this I hope you got some organizations I know I didn't go into descriptions but because this video is getting a bit longer um so I didn't really focus on that but I promis to go over that in another video uh we'll get there but um hopefully you see the purpose in how you can create functions and make it a lot more organized um and not a chaotic mess so I hope that was very useful so feel free to hit this subscribe like comment join Discord all the self promo stuff it's great having you guys see you next time
Info
Channel: MrButier
Views: 281
Rating: undefined out of 5
Keywords: blueprints, unreal, ue5, unreal engine 5, stats, code, tutorial, unreal engine, ue5 beginner tutorial, unreal engine 5 beginner, game development
Id: PhzSmzg4Zbs
Channel Id: undefined
Length: 45min 5sec (2705 seconds)
Published: Sat Mar 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.