Creating a factory style game in Unreal Engine 5.2 - Episode 18 - Resource Nodes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] Factory building code along series um what I was going to look at today and we'll jump straight into it was um resource nodes now the idea I want for this is basically to have the resource nodes way way way down underground but I don't need to place them there um we can kind of cheat with that now they can be just sat on the surface but they're going to be invisible so you won't see um anything graphical though we could have a graphical marker that we can use for debug purposes and switch it on and off depending if we're uh doing a bit of debugging but yeah let me jump into it I'll kind of show you as I go along what my thoughts are so we're going to blueprints and we'll create a new folder in here and we called it resources okay let me give this a color as well let's set it's a nice color uh what haven't we got in here um yeah there we go a really kind of Dusky pinky kind of thingy yeah strange one okay so I'm going to create a blueprint for our base and it's just going to be an actor and this will be BP resource underscore bass just like everything else because if we're going to have different resources then we want to be able to create different versions of this space on the resource so we don't want to have to you know um just hard code every single one we want you know if they share common elements you know make a base class that's always the best way it allows you also to search all your different classes just using this one if you want to find every single node regardless of what they are so it just makes things a lot easier anyway let's get inside of our lock that up there our resource base so what do we want well we don't want to be able to see this but we do um so what's the best way around this we want some sort of debugging so we can view where we place this yeah so what I'm going to do is I'm going to create a basic material um and that is because I want it to look a bit different now did we create a material folder no we're going to put I'll put it in the same folder let's go back to it resources so in here I'm just going to create a folder called materials this can be for across the board this game let's go inside that and we want to create a new material and we're going to call this M for material underscore um debug resource no it's a bit of a magical but at least we know what it means let's just open that up um so what we want for this is we want to keep it a service um I am going to I'm going to leave it on a pike and I'll set this just to unlit just to give us the emissive color only that's all we want um now what we can do here if we hold down three on the keyboard and click and we get ourselves a constant feedback so actually no let's let's not use that sorry let's not use that we're going to get um oh that's not what I wanted I want a vector parameter and we're going to call this um debug node color you can spell it how you like I spell it the original way the English way as that's the way I was brought up I'm going to plug that straight into the emissive um this is the color of the node so I want to say set the default one to just just to White I think just for now okay now yeah just boring old white nothing spectacular about it if you click anywhere on the white space here or gray space even on the grid let's make this a wire a wireframe um a wireframe texture now have they moved where they put it is it like further down is it like somewhere have I missed it have I gone straight past it let's just type in the search here where framework in advanced there we go and we will make it also double-sided which is up here at the top double-sided there we go not bad at all so now we've got this double-sided white color node we can now use this as our material for our node debug object what I'm also going to do is I'm going to add in um a scalar parameters actually hold s on the keyboard and click left click you get a scanner parameter I'm going to call this glow okay and then from here if we drag out and put multiply okay and plug the output into there as you can see nothing's changed but when I plug this in Watch What Happens hey it goes completely black it's because there's a default value of zero in there so if I put one it should go back to normal but if I put it in some like 10 it starts to Glow yeah and you could go you know crazy values look at that way too right uh let's try 100. look at that for a glow now the only reason I put this in here is when debugging um the idea of the planet I'm going to be on is going to be quite dark and dingy and very um the idea is to have it very stormy I want this one to be the most inhospitable places you could ever manage to be but you've still got to go out there and work and get your resources so that's that's kind of be the kind of Target I'm looking at so I want to be able to put this glow in there so if I'm looking for a resource node I can make them glow yeah and the reason I can do that is because I've got this value here so I'm going to set that for now just to just a light glow just 10. there we go just a light little glow and Supply that and Save and then we'll close that and then if we open the constant drawer again and we're going to right click and we're going to create a material instance and what I normally do is I use the same name it's going to give me an error but all I do is I add an i for m i for material instance there we go and now if we come in here we can change this glow here we can also change the debug color so if I wanted a a red because of the glow it's it's more orangey but it's the way the glow works yeah any color I kind of want just by changing it around yeah give it like a nice green so we'll save that come on out of that so that's all saved now so they're in our content drawer we've got this glowing material material instance now we could create different ones depending on the type of resource node is um but right now I'm just going to make them all in the base this default green so what we're going to have in here so I think that all we're going to need is a couple of things I'm going to have a node on the ground and possibly something that reaches up into the sky to give it a bit of an indicator of where it's at and if anyone's saw a beacon in Minecraft if you've uh played that at all you'll understand what I mean now maybe it's not going to reach as high as that but who knows um we could actually modify that as we go so what are we going to do in here we're going to add in our debug ground object so we're going to add just a straightforward sphere okay it's one meter that'll be fine should be fine 100 and we'll call this debug sphere and just compile that right so we go go just set the texture on this and my details panel is missing over here where is it gone um there we go I like having this details panel open some people don't I like it right there I couldn't mess around with it so this is default scale one meter yeah here's my material just says basic shape so if I come in here highlight my debug uh with debug recess now the green one and if I hit this little arrow and there we go if I unselect it I can't unselect it can I yes I can as you can see I can see my nice green glow yeah now where is this place is it underground or overground is it wobbling free there we go sorry none of you probably know what that reference means um The Wombles were really odd um property type kids program I used to watch back in the 80s 90s probably the 80s yeah you don't want to lock it up really strange so there we go we have this um sphere and it's actually going through the ground I don't need to modify I'm going to keep it as it is no it's visible we could make it not visible we could make it hidden in game now that's how we're going to do this um we're going to link this to a variable so that we can change whether it's viewable in game do we just have it on an event probably yeah we I don't think we need to set a Boolean value to say whether it's on or off because we can just read the actor hidden in game can't we um sorry the visible um tab so if we go into the events graph and we'll create a new event so custom event add custom event and we'll call this toggle visible uh we'll call it let's keep it constant debug toggle visible yeah we will put an input onto it so if we click the plus here on inputs and we'll have a Boolean variable and we'll just say visible okay and then all we need to do is just drag off here and we can go set oh no let's drag in the debug sphere first would help and then from there set visibility okay drag that in link it up bring that above and we'll drag the visible into new visibility now you have got proper propagate to children so I might use that and then everything else can be put underneath there so that we only have to toggle the one value so propagate to charge means that any children that I tag along to this sphere will also change their visibility and there we go so let's go into our prototyping channel uh can we expose this to editor you can expose it to cinematics can we expose this to editor yeah calling editor there we go you'll see what this does this is just helps you for debugging purposes tick this calling editor it doesn't matter in game you can leave this switch on because no one can use it um it's just full while we're in the editor so I'm going to bring one of these out so let's come into our resource and there we go as you can see it's half in the ground half nut okay let's deselect it there we go that's just its uh edit a second as you can see it's glowing um but if we scroll down we should always hit the top let's have a look oh I've got a selected first scroll down we should have a button somewhere where is it going where's it going okay it's possible but it didn't show up because I haven't um yeah because of this let's just disconnect this for now and remove that and we'll see and then come back in and there should be them in the details panel a button there we go debug toggle visibility but obviously it's only going one way because I have I've had to change the way I coat it so all I've got to do here is use the current visibility so we'll get its visibility and so is it visible and we'll set it to not Boolean so if it is visible it will switch to not visible yeah and if it's not visible it'll switch to visible I hope that's I understand that that's how the nut works it reverses this value to the opposite so true to false and false to true compile save prototyping so now if I toggle yeah toggle toggles it on and off just helps you when you're debugging you can just go along say well where's this resource mode toggle it there we go right not so simple as that obviously because you could be miles away depending on the size of your level but there we go so let's toggle it back on and that's working in the editor as you can see isn't it you know having hit play this is play I'm not sure if it works in here which would be interesting um have I got the resource node in here where is the resource node I can't do it there it is oh it does even better so as you can see I could toggle it on and off there we go I'm going to change the glow on that material so let's come to our material instance here I'm going to tip the glow I'm going to set that to half of what it was there we go not too bad not too bad save that and close come back to here that's better not too much of a glow yeah it's not too much of a glow um I might also turn off the Shadows on this object we don't want to be receiving Shadows on an object that's just a debug so all things like this you need to consider when you make things um so if you come to our debug sphere I've returned in here oh not sure what accidentally press the key shadow um cash Shadow there we go don't want any shadow there we go and it won't cast a shadow there we go no need to uh slow your game down any more than that's what's really needed so as we have that now what I was going to do is add in um a pillar didn't we so we're going to add in um it's not there by default so we have this there we go cylinder and we'll call this um light pillar yeah you spell pillow is it pillar pillar it doesn't look right either way I know that as you can see this is enormous let's clear that um I like pillar it's enormous but that's fine we want our scale to be this one like quarter maybe it's a 0.25 0.25 that's better now the height we probably want this quite tall to be seen from a distance um it depends on your rendering it just helps you when you you know you're nearby the location you can get a little bit closer so we're going to make this probably about um it's right 500 meters yeah and the location on the Zed um does that work no no no no it's a lot more than 500 okay so if I five thousand it's a very big pillar by the way that's more like it isn't it yeah I don't mind if it being underground it might be way too uh big as it is um but we'll say let's let's have a look in game um it's very big it might be okay so resource base let's come back into here light pillar and we're going to change the material on this to be the side so we're going to use our new material on that so in the game if I hit play we can now see this pillar Let's uh I need to turn off the Shadows on that one as well haven't I let's run over here as you can see Fuller quite a distance we can see that resource node and this is just for debug purposes so I do apologize if this um is waffling on a bit but it's just to show you that if you're going to plant one of these things and they're going to be invisible you can switch them on yeah anyway let's just get back to that that works let's hide the Shadow on this one as well so no shadow there we have it so we now have something just to visualize our resource node um because what I want to be able to do is to have a special mode in the editor where we can just edit these when we walk up to them and try and edit them a lot easier but we'll if you can't see them it's going to make it awkward so if we can you know walk up to them go to them and say hey let's edit this one and then hopefully just save it away into the level it'll be a lot easier um but anyway that's later on that's way way down the log so we've got is to toggle the visibility on and off of our debug swear so what are we going to need now we're going to need a hell of a lot and I mean a hell of a lot of uh hell of a lot of information now for now I'm going to make an enum of the types of oars um just for Simplicity purposes later on down the low line I was probably use some sort of data table to store the different types of ores um and any pertaining information that they're going to need um I.E hardness you know so how what type of drill heads you're going to need to drill it so you know if you've got a standard drill tip and you're drilling into something that's really tough um like diamond you it's not going to work is it very well not unless you've got especially these tools so I'm going to use for now and enum but that will change this is just to get us going on here so let's create our enum and we'll do it in our resource folder because it's all linked to this so let's create blueprint enumeration so we're going to call this e for enum and we're going to say this as resource type now the reason I'm using resource and not all because it might not just be Oz you know there might be other things that we do let's double click this and all I'm going to do is add in three say so we'll do the usual so I've got iron um is that and then we've got um copper and we could have uh where else could we have see I'm not sure if aluminum is a minable ore or whether it's a man-made Ally I know it is an ally but I think it's a I think it's man-made I'm not sure might be minable let's not put aluminum in there for the moment um what else could we have random or there okay so that's our ore type so in our resource we're going to have four oh sorry resource type okay and that's going to be of Type e underscore resource type and we'll make that viewable for now compile that and then we can clear that out the way I actually want to collapses these things I've got any advance all right so it defaults I am ferrite that's fine I don't mind that leave like that okay so we now have a type um all the difficulty and all that is going to be linked to this so I'm not going to put them in at the moment but what I am going to do is I'm going to add in a number of variables to where this or is so it's all node it's going to need a depth now this is going to be just a float we'll make that visible we'll make it dispose and spawn okay so this one this resource is going to be maybe I don't know let's say let's just say it's 100 meters yeah meter under ground two top of all now there we go so that's that's to the first stage okay what I was planning on doing is having um having kind of a a depth to different quality ores so what we could say is um that we have a default quality to the or node now in games like satisfactory and probably other games as well they have like normal poor quality um pure quality that sort of thing um no I do want to do that but I want each resource now to be different I don't want it just to be oh pure you're going to get this and much all right I want them to be a little bit of a a difference so let's create a new genome again so blueprint so right click blueprint enumeration I'm going to call this e um pure it's a oh no let's keep it resource you can't even spell resource purity okay and this all there's all going to be different values on how iron books like or copper they're going to have different values depending on their purity so let's open that up so we're gonna have um poor I'll put poor quality that's not the word I want to use I'll have a proper think I'll put normal purity and then pure well let's see looks like quality right so we'll start with just those these might change um and again this is where we're going to need a data table to get this information from so an all Iron node it's Purity might be different level of um fine refinery to a copper so you know a pure or node might give you quite a large amount of ore but a pure copper node might give you say a fraction of that or half of it or 75 of it so they're all going to have their own individual settings so for now let's just add those in and get that in here um I might change this to the center depth to be honest um yeah that might be the center death we'll work on this as we go along so let's just add in our Purity nodes here and we're going to put that as e underscore and pure resource Purity there we go okay let's make that an exposing spawn compile we're going to set this on just to normal so we can set that as the default right so now we have a purity and then we have a recess type so there we've got a depth now this is going to be the center depth so let's make this deep as I say this this one's centered at around about I don't know 1200 and we're talking meters here and I'll say that to center of the ore now you're asking why am I doing this why do I need this value well that's because I am going to be also setting different values to how far you draw so say you drill down and you only have enough uh drilling poles to get down to 1000 meters not 1200. you're not going to get the full intake of Purity yeah so your resource rate will be the same because the drill will have a resource rate but your Purity is going to change so we're going to have a separate Purity here obviously uh this here A Normal um normal port or pure but then there's going to be a calculation based on the distance of what the actual Purity value will be sounds a bit complicated so it might not be explaining this very well but as we go along you'll understand it so what we're going to do is we're going to create so if you come back in here right click create blueprint and structure we're going to call this resource depth quality that quality is it's not quality are you sure it's depth I will call it quality for now for ones of a better word it's not actually quality what is going to happen here this is going to describe at what depth what amount of or or do we do we do it by quality there's two ways we could do this we can either say right 1200 you're going to get the optimum amount of all um at 1000 you might only get half that amount and at 800 you might just get like a quarter and then anything less than that you might not get any that's one way of doing it another way of doing it is change the purity so in the center of the node you're going to get pure um all the best you can get out of the Purity so whatever level the Purity is you're going to get the best level and then as you come away the Purity is going to be worse so but for now I think I'm going to settle on um a quantity um but then there's also going to be other things involved including the refiner to actually what that quantity ends up being based on a percentage of um about all sorts of things based on his Purity and based on its um based on the refiners um level you know might be a level one Refinery or might only be able to extract half the amount of or out of yeah with the audits there the drill is always going to bring it up yeah so it's always going to bring it up so it's the refiner where how your refiner works and whether it can uh handle more so in here I'm going to have a float I'm going to call this um start range and then we're going to add another variable again and this is going to be end range and then we're going to add another variable and this will be um modifier okay so what will this will do is this will allow us to do a calculation based on the ranges that we set now we can set these ourselves or we can set them pragmatically using a random generator or we can just set them hard-coded values we could use okay we can choose what we like so inside the resource base we're going to add in our what we call this or range modifier okay and we're going to change this to the type of if I just type depth it should show up resource depth quality yeah that's not the right naming I will change that all right I'm now going to change that to an array okay so that means we can have an or deposit that's all different sizes um it could be small could be big you know so if it's a smaller deposit the range of quality might differ um so if it's a pure node you might only have a few different stages but if it's small those stages are going to be more tightly packed if you understand me so it's going to be a bit more of a guesswork yeah so what we can do now if we add in another variable be called um I don't know I've called that all range because it's a resource resource um radius and that will just be a float and make that visible and explosion spawn so by default we could say that you know we don't want that as a and array either one that's a single pile save and we could say that the range of this is by default 500 meters so what this is now going to do it's going to be able to give us a different modifier we can have a bit of code in here that would create some random numbers to put into these range modifiers um or we could hard code them if you want to hard code if we click on here we can just go in here and hit these array elements and put some standard settings in um but obviously we wouldn't do it on this this is the base class but we we could do it on these but we can we could modify them later but we might want to do it on our trial class so if I make a resource um of iron ore then we could in there start adding our range modifiers like I said it can only be pragmatically or it could be hard-coded so if you wanted a hard code some ranges so you just click the plus here make sure you've highlighted the oil range modifier come here and we'll say we're at the start range would be now we know it's 500 radius so 1200 minus 500 700 so 700 not sorry zero to 699 modifier will be zero okay now if we detect a modifier zero we're going to use a multiplication as the modifier so if you times by zero you get zero so that means anything between 0 and 699 in depth returns you nothing okay then we'll add in another one and this one will be 700 to let's say 900 yeah the modifier on this one will be say we're going to have three different ranges yeah so this one will be point two five yep 0.25 so we'll get a quarter if we hit that Mark I know this is a bit of a different mechanic than watching most games I was trying to be a little bit different so this is just going to be some default settings by the way these can all be changed in our when we create our new um all things we can also say use a table and so forth to do everything like that so let's actually let's keep those expanded so we can see them add another one and luckily I'll use them again typical now this one's going to be 50 or yes a 902 1000 yep and we're going to get 0.5 yeah now this is going to be the the set modifier we're also going to times it by a valued based on its purity yeah so if this is a pure vein it will get 0.5 if it's not a pure Vine we'll multiply that by another modifier inside so this half is then Times by maybe 75 percent you only get you know 75 of that half yeah just makes things a little bit more uh varied I would say but we'll we'll figure those out there's a lot of balancing to do with things like that to see how it works but I think this is an interesting way of doing it so let's have the new one um oh I keep forgetting we can't put these random numbers in there's going to be eight nine nine and this has to be 999 and this one's going to be 1000 to 1099 okay and this one is going to be 0.75 and then we add one more and this one will be so we got to 10.99 so yep this will be 1100 to 1200 inclusive okay and that will be a modifier of one now we do have a slight problem because then we could go past these so we would have to possibly calculate numbers going past but we won't at the moment we could just say it misses and you know let's just add the last one in that if it misses let's just let's give it a radius of about you know 200 me 100 meters so say 1300. yeah so that goes 100 either side of the center modifier of one and then anything let's make that 12.99 and then anything from 1300 to yeah anything from thirteen hundred we'll have a a modifier of zero um and if I put minus one in there we can detect that minus one as the last figure figure yeah which means that 1302 doesn't matter what number will be the last figure yeah just lets us detect it so now we have a range of values so we get nothing up to 699 then we get 25 of the ore between seven hundred and eight nine nine and then between 999 we get 50 of the ore at 1 000 to 1099 we get 75 of the ore and then between 1100 and 12.99 we get 100 of the or one yeah but then anything over 1300 no or so thirteen hundred and over detected by the minus one yeah we'll get nothing yeah so that will just fall back into this range so then we can detect how deep you drill but that unfortunately won't be detected inside this so we won't be showing you the code inside this until we make a minor and we all have to create a minor um it's only going to be something basic I'm not going to create anything graphically intensive yet um not yet anyway but so we now have a resource radius of 500. so that means it's a radius of that means a diameter of a thousand if we covered that thousand we might not need this radius that's for pragmatically adding this but this isn't so but if I did work it out 1200 minus 500 yeah but we're not going to do the other side of the radius we're just going to do yeah we're not going to do the other side so we haven't got a diameter we've got a radius only so then we can also use a modifier of Purity and depth and everything it's all in there so that's our base depth so that's a we might not need this either but that might just be for visual purposes for detection purposes um so we've got a resource type I don't feel right depth so the depth to the center of the o um the purity another modifier and all range modifier to allow us to know what what modifiers we get and the radius of that we don't actually need these rates so don't think I'm going to leave it there for now in case um in case we do go pragmatically because we might be able to add some random values in because if it's a pure node maybe it's got a wider Center core which is more pure so that you know you have a range of like I don't know maybe 200 radius that's 400 diameter for a pure one um or we can randomly generate a number within a range of say 100 to 200 or 300 so it'll randomly make those values for us but for now we've programmed them in it's not a problem so to be honest as far as a resource node goes for now that's workable we can now use that and place it in the world and it has information yeah but obviously this is the base class so all we're going to do now before we finish up this episode is take our base class right click create child blueprint class okay and we're going to call this BP resource underscore i n okay here we go let's zoom in it's really far zoomed out that is I don't know why I'm not sure why it's so far out that is really far that is like just it matters not it matters not so we have iron ferrite we can choose couple or book site and the depth is 1200 we could change it to whatever we like normal Purity and our range modifiers are all in here because this is all into the class defaults if you remember and so that's how that works on there so we drag one of those into the world uh which we already have definitely there we go we have this one in the world and that's just the resource base actually so let's take that one out because we don't need that do we why am I so far away I don't get why I'm so far away sure wasn't this far before strange there we go so let's delete that and we're going to bring in our iron so we have an iron ferrite resource node yeah I might even just leave this as BP resource and not use the iron because we have it here as you can see we can toggle the visibility still set all our ranges and so forth so now we have the resource node we can make it invisible but it is still there as you can see that's what this is so we can still lock to those we can still choose those um but what I'm going to do is try and place these in our grid properly um I may even make a tool for the editor to do so but I'm not going to go crazy at the moment but at the moment we have a resource now and we can switch it on and off for viewing and yet it's just to make it easier to find um because there might even be a debug mode in the game where we can change that as well so that if you're playing we want to test a few things we can say right here's this manager if we do that yeah there's that note I was looking for that one there we go but then obviously if uh oh that's what I want to do if I wanted to switch this off I'll just toggle that that means well I can't see everybody is there believe me it's there yeah okay nothing fantastic in this episode and all we've done is create a node it's all we've done but in the next episode I'm going to build a basic um Miner and we'll have a work and a play on how that's going to interact with this node so we need to set this in a proper location and we then need to attach the uh they've done the refiner The Miner above it and then the miner will then as it's locked to this because it's going to detect it and lock to it yeah so we replaced the building it will lock to it um by because we can have a view on there so we say we select the Builder tool and we select a miner um it might have a different icon that appears and says right okay and it can just give you a value of what's below it and so obviously if this has a radius but say there's a rock here I don't really want to do that but we might do you might not be able to get it so we might be able to face it we have to place the miner here but as we've set a radius as long as we're within the radius of the actual resource yeah we should get a region of it now obviously it's going to have to work um within our modifiers as well so we have to multiply this as well um for a right hand radius so we have to make a little bit of math so I might just use it cubic rather than rather than circular um could use circular but no we'll keep it queue because keep it easy but we can move across have it here and then we've got to add the modifier on so obviously if it goes out of the range of the 500 if I place um a minor too far away it's not going to get much of the uh The Ore is it but now obviously this is a meter Square we've got quite a large area here I could place the mine all the way over here as long as it's in within the radius but we also need to work out the modifiers it works but we'll work on that so next episode make a minor and let's start mining this resource I hope that wasn't too boring to say it was a little bit different this one um because we're making just the resource nodes um it's you know just a little bit different to a normal episode because there's not much going on rather than a bit of setup so yeah I hope you enjoyed that I hope it's um give you a bit of insight of how this can work and I hope you took something from it and you can make it your own or you can carry on with the next episode and see how we get on with this okay well thanks for watching um I do appreciate all the views and the the subscriptions especially as well and the likes and the comments um I really do appreciate it keep them coming and it's all I can say um I am really glad that it's actually being useful to some people in some way or form so yeah thanks for watching and I'll see you next time take care bye
Info
Channel: CreativeVFX
Views: 210
Rating: undefined out of 5
Keywords:
Id: NOCDs45EDSg
Channel Id: undefined
Length: 48min 29sec (2909 seconds)
Published: Fri Jun 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.