[Music] hello everyone and welcome back to the course in this lesson we will learn about two very useful data types in unreal engine the enumerator and the structure these are user-defined types that can help us make our code more intuitive keep things organized and even allow us to pass a lot of data between blueprints in a convenient way let's get started so now that we're back in unreal let's take a look at the first data type for the lesson and that is the enumerator an enumerator is a user-defined list of options and it is user-defined
because we created as a separate asset in our content browser and we defined the items on our list this data type can be useful because we can use it to keep track of many different things while in a game such as the status of the player animation states etc but can also be very useful to further customize our blueprint classes and if you recall from one of our previous lessons here in the construction script we're using two different variables to customize the light color and light intensity of our light i would like to use an
enumerator to further customize our blueprint so let's go ahead and go into our map and right here in the content browser right click go to blueprints and right there towards the bottom you'll see enumeration go ahead and click it and let's name this enum color options double click to open and you see that we have a completely new interface for our enum we can add a description here and if we want to add an item to our list we simply click on add enumerator and you'll see that we have a display name and a description
so for this one we'll do something very simple let's go ahead and add here specific color and let's add another enumerator and let's enter random color go ahead and save it let's go back to our blueprint now here under variables we'll click on the plus sign and name our new variable color options can be named whatever you want and here under the variable type go ahead and go back to single click on the drop down list and look for the variable we just created which was enum color options so go ahead and type that in
the search bar and you'll see that it appears here as its own separate data type go ahead and click it let's go ahead and compile finally let's make this variable public by clicking on the eye icon let's go ahead and compile again and now if we go back to our map and we select our blueprint you'll see that we have a new option here called caller options in an enumerator appears as a drop down list inside the editor so if we click here you'll see that we can see both options and if we added a
description when you hover your mouse over you'll see that description appear so what is our goal here what i wanted to do is we already have a new color and intensity that is being applied on our construction script i would like to add a separate option where if we select random color we will then select a random color to apply to the light from an array so let's go back to our blueprint and now we'll simply drag and drop our color options to the construction script select get and here we have a reference to our
enum one of the cool things about enums is that you can use switch statements and we saw that in the previous lesson so if you drag and search for switch you'll see that immediately you have switch on enum underscore color options go ahead and click that and you'll see that immediately we have an execution pin that goes there and two output pins based on the options on our enum so predictably if we select specific color we would like to do the exact setup that we have here so let's go ahead and move this here and
put our enum in between here as such but now if we select random color we want to go ahead and change the color from one specific variable to a random item from an array so go ahead and copy this node and connect it but now instead of neolight color we want to change this to a random item so a very easy way to do that is we're going to duplicate new light color so right click select duplicate and let's name this colorless and now let's go to the variable type on the details panel and change
this to array let's go ahead and compile and now we have a list of colors so let's go ahead and add three or four random colors that we would like our light to have there you go let's go ahead and compile and save and now we have an array with random colors so let's grab our color list and drop it into our construction script select get and from here we'll drag and search for random and select random array item [Music] we're gonna disconnect this by removing the node and simply connect a random node here lastly
we want to disconnect the set intensity node from here and we'll move this to the front since we want this to be applicable no matter the options that we select let's go ahead and compile and save and now you see that we have two different things that will happen based on the selection from our enum so if we go back to our level and we again select our blueprint right now the default is specific color so as expected the color that we have selected here will be applied to the light but if we change our
color options to random color notice that now a random color from our color list is selected and if we duplicate our blueprint by pressing alt and drag notice now that as i move the blueprint in the level different colors are being applied because as i duplicate it with the random color selected we are then picking a random color every single time so i'm going to duplicate this a few more times and you'll notice something curious every time we drag our blueprint the color seems to change and that is a behavior that is on by default
for all the blueprints in unreal so if we go back to our blueprint here and click on class settings you'll see that we have an option here called run construction script on drag it's on by default if you want to take that out you can deselect it and then this will only be run every time we compile [Music] and if we go back to our blueprint here the original one let's switch from random color to specific color we see that now we have the specific color from our variable and every other blueprint has a random
color from the list and this is just one of many examples of how you can use an enumeration now let's go back to our blueprint and once again take a final look at our example the next data type we want to look at is called a structure or struct for short a structure is a way of grouping related variables in one place and those variables are called member variables but unlike arrays like we saw in the previous lesson a structure can contain many different data types within it so for example you could have a boolean
a float and even an enum inside a single struct so what i like to do for this example is basically recreate all of the options that we see here in one single structure for example we have a color list we have color options we have a new light color i would like to put all those values inside a single structure to keep things organized and more flexible so the first thing we'll do is let's go ahead and rename color options here to something a little bit better like color method so let's go ahead and rename
it and let's compile and now just like an enumeration we're going to create a struct inside our content browser so let's go ahead and go to our map here right click in our content browser go to blueprints and select structure at the bottom let's name this struct light color now go ahead and double click to open it and just like enumerations we have a custom interface for our struct so if we go back to our blueprint here we know that we have an enum which is going to give us the color method we have a
new light color which is going to be used for specific color and a list of colors which is going to be used for the random colors so let's first create our enum here and call it color method so let's go back and right here click on add variable and simply name the first one color method and right here the type will click on the dropdown and search for enum color options select it the next one if we go back the next one will be a specific color of type linear color so let's go back let's
call this variable specific color and the type click and search for linear color go ahead and select it and let's create one more variable click on add variable and for this one we'll call it color list and instead of a single variable we'll click here and we'll make this an array and we'll click on save now click on the tab that says default values and we're going to again add some default values here so for the specific color we're going to add a purple and for the color list let's add a few random colors and
when you're done simply click save now let's go back to our blueprint and just like before we're going to create a new variable click on the plus sign and call this color options and here instead of boolean we are going to set the type to struct light color go ahead and select it we're going to make this public by clicking on the eye icon and let's compile and now if we go back to our map with any of our blueprints selected you see that now we have a color options and if we expand this we
have all of the same options that we had above but instead of having them as separate variables we have them all organized in a nice collapsible category as you can see here again very useful for keeping all of our information and variables in one place let's go back and let's drag our new structure to the construction script and select get and here with the structure selected you can see that the default values are exactly what we would expect but if we drag from the pin we have very different options so go ahead and select break
struct for now and you'll see that we have all of the same options broken into separate pins the exact same options that we have here are now represented with individual pins on this breaks dropped node and all we need to do now is simply replace our variables with the pins that we have from our struct so we can replace color method with our pin here new light color with specific color and color list with caller list here we can compile save and if we go back you'll see that we have the exact same options but
now everything is running from our struct so now by default all of our blueprint copies here are using specific color and have this purple so let's go ahead and delete all of the copies except one and now let's go ahead and just select the first one and you can see here we have specific color if we change this to random [Music] now you see that a random color is being selected every time so if you can duplicate this you can see the exact same behavior as we saw before except that now everything is being driven
from our single structure so if we go back to our blueprint we can now simply delete all of the older variables because we no longer need them and let's go ahead and compile and save and if we go back you can see that all of our information is now contained in one single structure called color options another interesting thing about structures is that you can have a structure within a structure so if we go back to our blueprint here we can see that we have all of our color options as part of our single struct
but what if we wanted to have an even higher level structure that includes for example the intensity and maybe some other properties if we click on our point light here let's go ahead and find one more property that we want to include we already have intensity how about we do cast shadows that'll be an interesting one here it's a boolean so let's go back to our map and let's again right click go to blueprints let's create another structure and let's call this struct light property let's go ahead and open it [Music] and just like before
let's go ahead and add both of those properties if we go back to our actor cast shadows is a boolean so let's add that let's go back again the next one is intensity which is a float let's add it and finally let us go ahead and add our light options which is a struct called light color so you can see here so let's go back here and add a new variable and let's call it light options or actually let's call it color options and we're going to have the data type struct light color go ahead
and select it and let's go ahead and say if we go to the default values tab you can see that now we have a cast shadows boolean a light intensity which by default is zero we can change that to 5000 and if we expand the color options we have all of the same options that we've had in our other struct so you can see that we're nesting a struct within a struct to create a much more complex structure with all of our options in one place so let's go ahead and save and let's add this
to our blueprint so go back to generic actor and let's add a new variable and call it light options in this case yet again we're going to use struct light properties and you can see it right here selected let's make this public and for now the other color options let's go ahead and make this none public now we're going to simply drag light options select get and just like before we want to break the struct so drag and select break struct and you can see now that we have the two properties plus the color options
that we had here before so just like before we can drag and select break struck and now we are basically back to where we were before except that now we have two additional options so here's a cool trick if you select control and drag from from one of the pins here you can actually grab the connection and drop it somewhere else so control click control click now we've replaced all of those properties here we can go ahead and remove this but in addition we have light intensity which we can now replace with this variable like
so we can remove this and finally we have cast shadow so let's make a little bit more space here for that copy point light drag and look for cast shadows set cast shadows go ahead and connect it and let's move this back and finally let's connect cast shadows to new valley as you can see here our example now drives all of our properties from a single struct let's organize this a little bit more there you go let's go ahead and compile and finally let's remove color options since we're no longer using it we can also
remove new intensity since we're not using that either and let's go ahead and compile now when we finally go back to our map and select either one of our generic actors you can see that now we have light options and when we expand we have those properties like cast shadows and color options so you can see that right now if we zoom in we are not casting any shadows but if we click here now we are notice the difference here as i toggle cast shadow you can see the difference here we can also change the
light intensity right here and finally we can go back to our color options and change from specific color in this case to a random color we can do the same thing here by simply changing our settings and again random color one last thing i want to show before we close the video is how to change a member variable within our code so if we go back to our light property structure we notice that the default value for cast shadows for example is false let's say that we wanted to change that within our code we can
go back to our blueprint here and here we want to zoom in here we can drag from the reference instead of breaking our struct which is what we used before we're going to select set members in the struct as you can see we only have a struct reference and a struct out pin but if we want to change a specific member variable with the node selected we can go back to our details panel and under the default categories we can expose these properties as individual pins so if we wanted to change cast shadows we simply
click on the check box and as you can see here we now have that node exposed so let's go ahead and connect this and now all we need to do is enable the checkbox and now if we compile go back to our blueprint we'll see that the default value has now changed if we click on this instance of our class if you recall before it was false and now it is true so as you can see structures can help us keep our code organized and as you'll see later in the course they make passing related
data between blueprints more convenient let's do a quick recap we learned about the enumerator and how it is a user-defined list of options we can create as an asset in unreal engine we saw how it displaces a drop down menu inside the editor and how we can use it with a switch statement to customize our blueprint classes we also learned about structures and how they can contain a group of different variable types we saw how we can embed structures within structures to create a more complex grouping of variables structures can help us keep our code
organized and allow for a more intuitive grouping of parameters if you want to practice what we learned go back to our blueprint and add additional variables to our light option structure to further customize the class and that's all for this lesson thank you so much for watching and i'll see you on the next one [Music] you