Create Modular Designs With Enums In Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so today we're going to dive into the basic concepts behind a modular design system using blueprints inside of Unreal Engine and we're going to take a look at it from the perspective of wall variations when you're constructing a building so let's say we're designing a map with a building and we start with a solid wall well what if we need that wall to have a window [Music] or what if we need that wall to have a door using blueprint in unreal it's actually really easy for us to build a simple system that will allow us to quickly switch out these wall Types on the Fly and what's even better is that once you know how to do this you can apply this concept to anything that you can imagine that can make use of variations all right let's go ahead and get started all right so to get started with this task we're going to use one main data type that's going to help us out here and that's called an enumeration or enum for short but what exactly is an enumeration well an enumeration is a set of values where you have an integer that is tied to a string or in other words you have a number that is tied to a word so let's look at an example let's say we have an enum of one two and three now we can have one equals one two equals two and three equals three of course we could also have something like 1 equals red 2 equals green and three equals blue we could even add a 4 in there equals Alpha if you wanted to go rgba but of course these don't have to be related at all because these are just a set of values where the number is equal to the word so we could for example say one equals koala two equals banana and three equals fire truck completely unrelated things unless you happen to have a koala eating a banana in a fire truck but that is a story for another time admirations are really powerful in programming and they're really powerful and unreal and one of the greatest things about an enumeration inside of unreal is that when you're using an enum as a variable in a blueprint it shows up as a drop down box in the details panel so you can very easily just go in and select the drop down box and select what item you want from it this is really powerful when you're trying to do some kind of variations with your blueprints so let's go ahead and dive in and get started on this see you in unreal all right here we are inside of Unreal Engine 5.1 I've created a new project uh using the blank template from the games category I did include the starter content and this is going to be really important right here because inside of the starter content there is this folder called architecture and this is going to have the meshes that we're going to use for our system here if we go ahead and dive into this folder we can see we've got some wall types over here a solid one a window one and a door one so first off right off the bat let's go back up to content here and then I'm going to go up here to file new level and I'm just going to select basic go ahead and hit create there we go now we want to start creating our folder structure and we want to save this map right off the bat so what I'm going to do is in content I'm going to right click I'm going to go to new folder and I'm going to call this modularity just like that now inside of modularity I'm going to right click and do new folder again and this time I'm going to type Maps so this is going to be the folder where we're going to save this map right here so right off the bat go up to file come down to save current level as make sure we're inside of this Maps folder and I'm going to call this modularity demo just like that so I'll hit save and there we go now we can see that it is in this folder all right next up let's go ahead and look at these architecture pieces that we have available so back up in content starter content architecture we'll see that we have a few wall pieces here we have a couple of different sizes we have 400 by 300 and we have 400 by 400 now 400 is the width in both of these in this one it's 300 tall in this one it's 400 tall we're gonna go ahead and stick with the 400 by 400 just to keep it as a kind of consistent Square all right so let's just have a look at these real fast I'm going to drag this out into the world like that there we go if I drag the door one and I drag the window one we'll see these three different variants that we're going to be working with here and we're going to be setting up a blueprint that's going to let us easily switch between those so for now let's go ahead and select all of them and delete okay so now go into our content back in our modularity folder here and now I'm going to create another new folder and I'm going to call this blueprint just like that now side of this blueprint folder I'm going to right click and go up to blueprint class now what type of blueprint class are we going to do we're just going to do an actor the top one here simple one so I'll click on that we'll see this new blueprint pop up I'm going to call it BP underscore modular wall just like that now if I were to drag this out into the world we'll see that nothing is there but the icon itself and that's because we haven't actually added anything to this yet let's go ahead and do that now by double click to open this up there we go [Music] here in the blueprint editor the first thing that I'm going to do is come over here to the components section I'm going to click this add button and come down here to static mesh and then here I'm just going to type in wall mesh just like that now we have this mesh here but currently there is nothing in it and if we look over here on the details side we find the static mesh section we'll see static mesh and currently it is set to none if we were to click on this drop down we can see all the different static meshes in this project that we could assign to this but that can be a little bit cumbersome so for now it's uh unmaximize that I'm going to go into my content folder back into starter contents architecture and we're gonna grab this wall 400 by 400 now when I do that with that selected in the content browser if I come back into my blueprint come down to static mesh and we see this little arrow here use selected asset from content browser if I were to click on this that's going to assign this wall right here so now if I were to hit compile we'll see that this particular blueprint here now has this wall assigned so next up before I do anything else I want to look at the snapping tools inside of unreal here this is going to be really important when we're working with modular pieces so if we look in the viewport up in this upper right hand area here we're going to see all these little things what we want to look for is the one that has this little grid symbol right here now this is for movement when I have this selected and it'll be blue that means that snapping is turned on so you can see right now if I were to alt drag this out we can see how it jumps as I move it but if I were to click this and turn it off so that it's gray we'll see that it's free moving now this is a little bit more difficult to line things up and you don't want to actually spend the time to go in here and try and line this stuff up that's going to be too hard so it's much easier to work with snapping on so I'm going to go ahead and delete this guy I'm going to turn on snapping and if we look next to that icon we'll see this number right now I have mine set to 100. this is the amount of units or in this case centimeters that the object is going to snap to as we move it so if you look at this drop down it can be as small as one for one centimeter uh we could have something like 10. we can see this very small step size uh we can set it to 50. a little bit bigger we can set it to something like five thousand and you'll see we'll have to zoom out to get these really large snap sizes but since these walls are 400 by 400 our best bet is going to be 100 since there isn't a 400 snapping size so we'll do 100 and that means if I were to hold down Alt and hover over this and drag a duplicate out we can see how nice and easy this guy snaps right up to this so now you can drag another one out while holding alt and create a sort of wall system over here kind of a building so then I could rotate it like that get myself a little corner there right so that with the snapping is going to be really important for this modularity all right now let's get into building out this blueprint so if I come over here to my modularity folder I'm going to go back into blueprint here and now I'm going to right click and create another new folder I'm going to call this helpers now if I go inside this folder and right click we're going to do something a little bit different this time instead of going up to blueprint class we're going to come over here to the blueprint section under create Advanced asset we'll get a little fly out and we're going to come down to this enumeration here now if I click on that I'm going to call this e underscore wall types just like that if I double click to open it up we'll get a new type of window and we'll see this button here it says Addy numerator I'm going to go ahead and click on that and you'll see now we have this section called enumerators with one entry in it we have a display name and we have a description now we're not going to worry about description right now description is if you need to have tool tips inside of your engine what we're worried about is the display name so for here what we're going to do is we're going to type in Standard wall with Paschal casing all one word when we're working with the enumerator here we do need this to be one word no spaces so we use the Pascal casing where we have the first letter of each word capitalized so now we have a single entry in this enumeration called Standard wall if I click this two more times it's going to add two more let's go ahead and call the second one window wall and we'll call a third one door wall just like that click the little save icon there we go now we can go back over to our BP modular wall so what we need to do now is we're going to come over here to variables and under variables we're going to click on the plus sign to add a new one and I'm going to call this wall type Now by default it's going to create it as a Boolean we don't want this to be a Boolean we want to actually set this Boolean this uh variable type to our enumeration that we just created so how we're going to do that is we click on the drop down and we'll see that it doesn't show up in this list here it will show up under enum if we were to drop this down you can see it right there but a lot of times it's going to be difficult to find your custom data types like this in that list so a way we can find it is we can just go up here to the search box I'm going to type in wall and now we can see our wall types over here so if I select that we can't set a default value until we compile so let's come over here to our compile button up here we'll click that and then we'll see now our wall type variable is a drop down with our three options that we created for it so if I were to come over here to variables and we're going to find this little eye icon over here on the right side of it right now it's a closed eye if I click it it'll be an open eye if I were to hit compile then now if we come into here and we select one of these we'll see over here in the details panel under default we now have wall type and we have this drop down right now changing it doesn't do anything because we haven't actually set anything up all right so let's go ahead and do that now we'll go back into our blueprint and we want to go into our construction script here now if you ever accidentally close this guy out and you can't find it you just come over here on this left hand side and you go to functions and you find construction script we're going to double click that and it's going to open it back up for you alright so now what we need to do is we're going to click and drag wall type out into our graph now for this we want to get it we don't want to set it we want to get it and now we get to see this really cool thing that blueprint lets us do with enumerations if I click on this little open circle here and drag out and then let go and then we type in switch we'll find this option called switch on E underscore wall types if we click on that it's going to create a node for us that is going to have some very familiar outputs you'll see that these outputs here are the same ones that we created for our enumeration so they tie in to whatever we have selected in the drop down so let's go ahead and drag out from our construction script to plug it in there and now the next thing that's going to happen in this blueprint is whatever this variable happens to have selected whatever it's set as the blueprint will choose to follow that path so the default here Standard wall is going to be one path window wall would be another door wall would be another so what do we want to do when that changes well we want to actually change the mesh that is being used how we're going to do that is we're going to come up here to our components we're going to find our wall mesh we're going to drag this out in here and what you'll notice is that when I drag it out it doesn't give me the option to get or set it and that's because you can't actually set it like this when it's a component over here so in order to change what this mesh is we need to drag off of this node and if I were to type in set we're going to find this set static mesh now what this node is going to do is it's going to take this mesh and it's going to set it to whatever we happen to set here so if I drag out and plug it in there and then we hit compile now everything goes away and that's because when we have Standard wall selected it's going to set the static mesh to nothing of course if we were to come over here and change this to window wall suddenly we get our Standard wall back the reason for that is because we don't have anything happening when we change this and we have our default here set to that wall so let's go ahead and clear that now if I with wall mesh selected under static mesh I find this little back arrow button go ahead and click that and now it's going to reset this to none so now what I want to do is I'm going to drag over this I'm gonna hit Ctrl d and it's going to duplicate those two nodes now if you're using Unreal Engine 4 that hotkey is actually control W but in Unreal Engine 5 it's Ctrl d so if I were to do this one more time now I have three sets and I'll just plug in each one of these just like that now the next thing I need to do is I need to actually set these so let's go ahead and go into our content starter content architecture and we want to make sure that we're grabbing the right things here so for the Standard wall I want this wall 400 by 400. so I can with it selected in the content browser come up here to this node and click the little arrow use asset browser selection and that'll assign it there we come down to window wall and I want this wall window 400 by 400. we'll sign that there and then for door wall we're going to do the same thing with the door we'll select it in the content browser and we'll assign it in the node now if I were to hit compile like that we'll see that our walls come back and if I were to select this one and then change this drop down to window wall suddenly it changes here if I come to this one and change it to door wall that'll change it there and what you can see in your blueprint graph here is when you select this Standard wall it's going to go this way when you select window wall it's going to follow this window wall path and when you select door wall it's going to follow this door wall path pretty simple right so what is the use case of this why would we ever want something like this well let's say you've got a setup like this and you know you do some play testing or your designers come in and you know you just find that you need to switch things around a bit but let's say we need to put the door here I can just now select it and go to door wall there we go set this one to a window wall set this one to a window wall and there you go but then maybe they don't want to have the window right up against this corner so everything needs to be shifted over again so it's really quick and easy to just change this to a door this to a window this do a standard wall and then maybe we'll turn this one to a window as well so setting up a system like this using enumerators for your selections makes it really easy to do some quick iterations on a process like this foreign [Music]
Info
Channel: Digital Alchemy
Views: 3,820
Rating: undefined out of 5
Keywords: unreal engine 5, unreal engine 5 beginner tips, unreal engine 5 tutorial, unreal engine 5 beginner, unreal engine tutorial, ue5 beginner tutorial, ue5 tutorial, unreal engine 5 beginner tutorial, 3d, game, epic games, fornite, epic games launcher, environment art, game industry, game career, john waynick, game art, game artist, game development, virtual production, ue4, UE 5.2, Unreal Engine 5.2, Blueprint, Enum, Enumeration, Enumerator, Blueprints, BP, unreal masterclass
Id: scWxNglInkk
Channel Id: undefined
Length: 24min 41sec (1481 seconds)
Published: Thu May 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.