How To Make A Hunger Bar In Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so the first thing you want to do is open up your first person character or third person character it doesn't really matter this is just a new blank project I created for the tutorial next inside here you want to come over here to your variables and you want to add two new variables the first one's going to be called current hunger and set this to a float and the next one's going to be another float and name this Max hunger compile and save so we can access these values and Max hunger we're going to set this to 100 and current hunger wherever you want your hunger bar to start out at 100 will be full 50 will be half etc etc whatever you want to start it out as so next we're going to create a function so click right here create function and call this hunger and instead of here we're just going to drag our current hunger drag it out get current hunger and do minus and just say in this just say one because we want the hunger bar to be as smooth as possible or you could even do like5 if you want to and then off of the subtract we're going to drag off and do clamp clamp float and our minimum value is going to be zero and our maximum value is going to be Max hunger and what this essentially does is it makes your a current h cannot go below zero or 100 or whatever value you set max hunger to be this comes into effect for the visuals of the hunger bar so that it doesn't go below zero and then you eat and then it becomes instead of becoming one say it becomes negative one it'll make more sense in just a minute so then drag out current hunger again but this time do Set current hunger and drag your clamp into that and drag the execute into the hunger all right so next we can compile and save this and just minimize this because we're not done with it and now wherever you're keeping your widgets and stuff this is where this next part will go but I'm just going to do it in the base content browser I'm just going to right click and do user interface widget blueprint user widget and I'm going to call this bpor hunger widget just like so and inside my widget I'm going to search for a canvas panel and drag this in if you're adding this widget into another widget then you probably won't need a canvas panel but I'm doing it because I'm going to be adding this directly to the viewport and next I'm going to clear the canvas panel from the search and then drag in an image right here the size X I want this to be 150 and size y 150 as well you can make it bigger or smaller depending on how big or small you want it and for the anchor right here I'm going to Anchor it into the bottom left corner right there and I'm going to call this hunger image and in the appearance right here I'm going to click this drop down for the image I'm going to search for tore meet which this is a texture that I got from opengameart.org I will leave a link to it down in the description below the license the licensing on it says it's completely free to use so you can double check if you want but as of my knowledge this is completely free to use and it comes with a bunch of other assets as well so next next to the meat we're going to search for a progress bar right here drag this onto the canvas panel as well and I'm going to put it roughly next to the meat right down here and I'm going to change the size X to like 250 maybe even 300 would be better just to give it a little more length and I'm just going to try to center it just a little bit better it doesn't have to be perfect especially for a tutorial but I just want it a little centered so now we can compile and save this widget and don't close this widget either but we can head back to the first person character or once again whatever character you're using and inside the event graph on begin play we're going to have to create this widget so drag off of just at the end here just drag off and do create create widget and for the owning player drag off of this and do get player controller and for the class right here open this up and search for bpor Hunger widget and then off of this return value we're going to rightclick and promote this to a variable and call this hunger widget ref this will make sense in just a moment and then off of this we're going to drag off of hunger widget ref and do add to viewport and now after we add the widget or we create the widget and we add it now we need to call our function over here that makes the health go or the hunger go down so to do that we have to drag off of this once again and do create timer by or I mean not create set timer by function name right here and we want to set this to looping and for the function name you want to make sure it matches hunger exactly and for the time value right here this is how fast your hunger will go down I find a value anywhere from like two or maybe even like 3 seconds is good and so now we have our hunger that'll actually go down and now we just have to update this widget and instead of creating a binding right here that gets called every like basically on tick just about instead of doing that what we are going to do is use this widget reference and we are going to update this bar right here but first make sure you set the bar fill to 100 or it will it'll be zero and then it'll jump up so just make sure you set this to 100 real quick and then compile and save that and yeah in the Hunger function we just want to drag our widget ref right here get widget rev drag off of this and do get progress bar 119 I didn't rename this so you could come over here and do rename and do hunger bar that' make a little more sense compile it and then you could just drag off and say get hunger bar like that and then off of get hunger bar we are going to do set percent right here and this is where our current hunger is going to plug into right there and now this makes a little more sense this clamp right here I mean this Max isn't really needed since we are just subtracting but it's good to add your limitations either way but as you can see the zero say we don't clamp it to zero and say this bar over here goes down to zero it's completely empty but say our float keeps going down to like -20 because we didn't clamp it like this bar can only go to zero but the float will be at -20 then you're going to have some issues so that's why we clamp it all right and so now if we test our hunger we press play as you can see we got our hunger bar down there in the bottom left and if we wait a few seconds it should go down hopefully ah I think I know when it's not going down so I forgot to divide this by 100 right here we are setting percent so it's on a scale of 0 to one basically so this needs to be divided by 100 because our health system is going from 0 to 100 so you just divide by your scale basically and so this makes it a percent right here and so now if we minimize this and press play then it should be all good to go and working yep as you can see the hunger bar is ticking down slowly but surely you can make it way slower than this like this is super fast like how this is going down like a lot you can go in here and adjust the settings I had that to five on accident instead 0 five for some reason and the time right here you could set this to even like 5 seconds if you wanted to or like 10 seconds like hunger is really supposed to go down at a really slow rate and just remember the lower the value and the slower you make it the smoother the bar will be if you make it super fast and high values then the bar will be will move in chunks and so yeah if you enjoyed this video leave a like subscribe for more and I will see you in the next one bye-bye
Info
Channel: The Average Dev
Views: 190
Rating: undefined out of 5
Keywords: unreal engine, how to make a hunger bar in unreal engine, unreal engine hunger bar, unreal engine tutorial, how to make a hunger bar in unreal engine tutorial, hunger bar in unreal engine, ue5, ue5 tutorial, hunger bar unreal engine tutorial, how to create a hunger bar in unreal engine, unreal engine hunger bar tutorial, unreal engine tutorial hunger bar, hunger bar, hunger bar tutorial, how to make a hunger bar
Id: M2hMGAkjxnM
Channel Id: undefined
Length: 9min 49sec (589 seconds)
Published: Sat Jan 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.