Class Blueprints can be used to make modular code. In this video, look at how one can be utilized to make a pickup whose color can be adjusted on the fly.
- [Instructor] Let's continue writing our script for this pickupColorChange Blueprint. So, the first thing I wanna do, is head back into my scene, and make sure that I have the right materials assigned to this, and just open up that material, so I can use it as a reference. So, pull up Material, and Pickup. And we wanna be working in the NEW_MAT instance that we created in the Materials section. So, go ahead, and just click this, and drag it into the pickup. That was it looks the same as what we are working with, and we can open that up, and refer to, we'll need to know the names of these parameters.
So, let's head back over to the pickupColorChange Blueprint. And we'll be working in the construction script, since we want this to change colors during the editor mode, as opposed to just when we click play. So, we'll begin by heading over to the Variables section, and go ahead and create a new variable, that we'll call Color. Essentially, this is gonna be where we will change this variable in the editor, and then it will run through this construction script, and set the new color within that material that we created.
So, if you see this little capsule shape next to the color, it's red to represent a Boolean variable type. So, if you head over to the Details panel, you can see where it shows that red for Boolean. If you click this drop-down, though, you'll see that they color-code every type of variable. There's all kinds of different variable types. But for our purposes, let's just type color, and we'll just choose the basic one. So, now that it's blue, we can go ahead and click this variable, and drag it out onto the scene.
Now, it will give us two options, Get or Set. So, for our purposes, we just want a reference to this color. We'll be setting this in the editor itself. And now, another important thing to note with variables is, there's this little icon here next to it. It's kind of a closed eye. That means that it's set to private, and so it can only be changed within the Blueprint. However, if we click this, so that it's open, now the variable is public, so when we look in the Details panel of the Blueprint, there should show up a reference to this variable type once we compile, and we'll get to that a little bit later.
For now, what we wanna do is, drag a line off of this execution pin, and drop that. What we're trying to do is, create a dynamic material instance. Essentially, it's a special type of material instance, that can be changed on the fly. So, we'll just type, create dynamic. And notice that there's a couple different options. There's just a Create Dynamic Material Instance, and one that's specific to the StaticMeshComponent.
Let's go ahead and click on that, and see what happens. So, you'll notice that it automatically pops in with a reference to this StaticMeshComponent, because it's the only component in the scene. That's nice and handy because we'll need a target from this. But you can always click this component, and drag it out into the scene, to create that same kind of reference. Now, before we can move on, we'll need to fill in the source material. Essentially, this is just asking for, what the name of that material is, that we're gonna be changing, and creating a dynamic material instance of.
So, you can just click on this Select Asset, or you can go to your content browser, and make sure you have your instance selected, and then within there, you can click this little left arrow, to automatically fill that in. But of course, you can always select the drop-down, or even type it in, and it's all the same. So now that we have our new material instance as our source, we can set the parameter values.
So, I could drag off of this execution pin, but instead I'm going to drag off this Return Value, which is essentially the new dynamic material instance that it's created, just so that we for sure will create the correct function, based on this variable type. So, now we'll click Set Vector Parameter Value. And notice, it automatically connects our execution pin.
So, it's asking for two inputs, the Parameter Name, and the color value. So, we can take our color node that we created earlier, go ahead and drag that in, and it will automatically create a little converter, to set it up to be the proper type of color variable that it's looking for. However, before we can do anything, we need to tell it which Parameter Name that we wanna actually set. So, if we head back over to the material, it's called main color.
And we wanna just type that in here, main color with a space. Now that it's all wired up, let's head over to Compile, make sure it's good to go, and then go back into our scene, and you'll notice that it automatically changed, according to that color that we just sort of randomly set. Now, because we set that color variable to public, it shows up here under this default tab.
And just to show you, if I turn this to private, compile it, that tab disappears. So, if you're ever working with this, and you realize that your variables aren't editable, it's usually because they're not set to public. And then again, you have to compile after every change to your Blueprint, otherwise it won't show up. And then, click on this color, and start to drag it around. Notice it's not changing. That's because it's value is set to zero, so let's bump this up.
And now you can see it dynamically change, directly from our asset. And that's how you can use construction scripts to create functionality within your scene.
- Customizing the Unreal UI
- Creating a new project
- Creating landscapes
- Blocking out levels
- Working with materials and lights
- Adding post-processing effects
- Adding atmospherics, foliage, and fog
- Working with the Blueprint editor
- Creating cinematics
- Monitoring performance
- Packaging a game for distribution