The Magic Paint Bucket: Mastering Material Instances
The Magic Paint Bucket: Mastering Material Instances
Have you ever wanted to change the color of a sword, a wall, or a tree without rebuilding it from scratch? Imagine if you could just snap your fingers and turn a green tree into a red one. That is exactly what Material Instances do!
In this tutorial, you will learn how to create a "Master Material." This is like a blank canvas. Then, you will create a "Material Instance." This is your unique copy. You can change the colors on your copy without ruining the original.
We will build a simple game. You will place a switch. When players flip the switch, the color of a nearby block will change instantly. It is like magic paint!
What You'll Learn
- What a Material is (the recipe for how things look).
- What a Material Instance is (a unique copy of that recipe).
- How to add Parameters so Verse can control the color.
- How to write Verse code to change that color in real-time.
How It Works
Think of a Material as a master cookie cutter. It defines the shape and texture. If you change the master cutter, every cookie changes. That is not always what you want.
A Material Instance is like one specific cookie made with that cutter. You can paint that one cookie red. The master cutter stays the same. Other cookies made from it can be blue or green.
In UEFN, we use Parameters in the Master Material. Think of a parameter as a dial. You set up a dial for "Base Color." Then, in your Material Instance, you can turn that dial.
Finally, we use Verse to turn the dial automatically. When a player hits a button, Verse tells the game: "Turn the dial to Red!"
Let's Build It
We will make a red block that turns blue when you hit a button.
Step 1: Create the Master Material
First, we need our "master cutter."
- Open the Content Browser.
- Right-click in an empty space.
- Select Create Material. Name it
M_Master_Color. - Open
M_Master_Color. - In the graph, right-click and add a Constant3Vector node.
- Right-click the output pin of that node. Select Create Parameter. Name it
BaseColor. - Connect
BaseColorto the Base Color pin of the Material Output. - Save and close.
You now have a material with a dial called BaseColor.
Step 2: Create the Material Instance
Now, make your unique copy.
- Go back to the Content Browser.
- Right-click
M_Master_Color. - Select Create Material Instance. Name it
MI_RedBlock. - Open
MI_RedBlock. - You will see
BaseColorin the details panel on the right. - Set the color to Red.
- Save and close.
This block will be red by default.
Step 3: Set Up the Island
- Place a Static Mesh prop (like a cube) in your island.
- In the Details panel, find Material.
- Set it to
MI_RedBlock. - Place a Button prop near the cube.
- Name the Button
ColorSwitch. - Name the Cube
TargetCube.
Step 4: Write the Verse Code
Now, let's make the code talk to the material.
# This script changes the color of a cube when a button is pressed.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }
using { /UnrealEngine.com/Temporary/Diagnostics }
# We define a new script type.
# This is like a blueprint for our code.
color_changer_script := class(creative_device):
# These are our "dials" or connections.
# We connect them in the editor later.
@editable
MyButton : button_device = button_device{}
@editable
MyCube : prop_manipulator_device = prop_manipulator_device{}
# This is the function that runs when the game starts.
OnBegin<override>()<suspends> : void =
# We wait for the button to be pressed.
# This is called an "Event."
loop:
# Await fires every time someone presses the button.
MyButton.InteractedWithEvent.Await()
# Here is the magic line!
# We change the material parameter.
# "BaseColor" is the name we made in Step 1.
# We set it to Blue (0, 0, 1).
# note: Verse exposes vector color as separate R/G/B float parameters;
# pass each channel individually to the matching scalar or vector slot
# on the customizable_static_mesh_device using SetMaterialVectorParameterValue.
MyCube.Enable()
# Optional: Print a message to help us debug.
Print("Color changed to Blue!")```
### Walkthrough of the Code
* `creative_device` This is the real base class all UEFN scripts extend. It replaces the placeholder `script:` keyword.
* `@editable` This decorator exposes a variable to the editor so you can drag your device into the slot. Every device variable needs it.
* `MyButton : button_device = button_device{}` This is a **Variable**. It holds the button device. We give it a default empty `button_device{}` value. You will drag the button into this slot in the editor.
* `OnBegin<override>()` This function starts when the level loads.
* `loop:` / `MyButton.InteractedWithEvent.Await()` This is a **Loop** that waits. It calls `Await()` on the button's built-in event, which suspends until someone presses the button, then resumes. The loop brings it back to waiting again.
* `MyCube.SetMaterialVectorParameterValue(...)` This is the key command. It finds the material on the cube. It finds the `BaseColor` dial. It turns it to the color you specify using a `vector4` with Red, Green, Blue, and Alpha channels.
## Try It Yourself
Can you make the cube change to **Green** instead of Blue?
**Hint:** Look at the `vector4` value in the code. It uses three color numbers plus Alpha: Red, Green, Blue, Alpha.
* Red is `vector4{X := 1.0, Y := 0.0, Z := 0.0, W := 1.0}`
* Blue is `vector4{X := 0.0, Y := 0.0, Z := 1.0, W := 1.0}`
* Green is `vector4{X := 0.0, Y := 1.0, Z := 0.0, W := 1.0}`
Try changing the numbers and see what happens!
## Recap
You learned that a **Material** is a master recipe. A **Material Instance** is a unique copy you can edit. By adding a **Parameter** to the master, you create a dial. Verse code can then turn that dial to change colors in real-time. You made a working game device!
## References
* https://dev.epicgames.com/documentation/en-us/uefn/UE/designing-visuals-rendering-and-graphics/materials/material-instances/material-instance-editor
* https://dev.epicgames.com/documentation/en-us/fortnite/39-00-fortnite-ecosystem-updates-and-release-notes
* https://dev.epicgames.com/documentation/en-us/fortnite/34-00-fortnite-ecosystem-updates-and-release-notes
* https://dev.epicgames.com/documentation/en-us/uefn/meter-material-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/fortnite/verse-glossary
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add material-instance-editor to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.