Materials Parameters in Blueprints - Tip of the Week

Michal Franczak 2019-10-09 11:39 tutorial  > Unreal Engine  > modeling

Unreal Engine 4 Tutorial.

Sometimes you may want to control material parameter in blueprint. It gives many advantages - you can control material parameter in sequence editor, or change it when you will approach certain area, change color of a wall with some input trigger (like gamepad or keyboard stroke). In this tip we will look at the part of creating material parameter and setting its value in blueprint. It's quite easy.

First, create Material Parameter Collection - it is kind of container for material parameters. 

nr_02019_Untitled

 

Then, open Material Parameter Collection and create your variables. You can create scalar variable for controlling single values (like aplha, masks, roughness amount, metallic amount) or vector variables for controlling colors.

 

nr_02032_Untitled

Here I have created Scalar Parameter with default value "0" and I gave it a name "PARAM01".

 

Now we can assign this parameter to some material property. Let's create new material and open node editor.

 

nr_02021_Untitled

In node editor find "Collection Parameter" and add it.

 

nr_02033_Untitled

We created material with some base color, metallic value of 1 and roughness assigned to Collection Parameter "PARAM01".

 

Now let's change the value of this parameter. We can do it in blueprint or in sequencer.

nr_02023_Untitled

To control this parameter in sequencer, create a new sequence and press green "Track" button. Then choose "Material Parameter Collection Track" > choose material parameter collection that you created. In our case it is collection named "MPC01".

 

nr_02024_Untitled

Choose "Parameter" > "PARAM01" from the list.

 

If you want to control parameter by blueprint, create new blueprint class > Actor and open it.

 

nr_02029_Untitled
 

On the top of Blueprint window you will find three tabs: "Viewport, Construction Script" and "Event Graph". We are interested in the third one. Click on "Event Graph" and let's start adding nodes. you can do it similar to material editor - by pressing right mouse button in editor window. Our first node will be "EventBeginPlay". This node launches the script after we press "Play" button in main editor window. 

 

nr_02030_Untitled

Our second node is "Timeline". We use timeline when we want to change some value in time. I want to change my material parameter value over time, so the timeline is the node I want. We connect EventBeginPlay with "Play from Start". This way each time when we press "Play" script will start from the very beginning of timeline. If we would plug it to "Start", with each press of "Play" we would start from some timeline moment.

 

nr_02034_Untitled

By doubleclicking Timeline node we open Timeline editor. We can create a new curve by rightclicking and creating points. Curve can be linear or bezier, it depends of shape of points we will choose. I created triangle linear wave. On the top you can see length: 3.00 seconds. I also checked "Loop", so timeline will play indefinitely after launching script, changing our value from 0 to 1 and back. Note that our track has the name "New Track_0".

 

nr_02035_Untitled

 

Our last node is "Set Vector Parameter Value" which is used to target our parameter in material. You can see "Collection" box, where we can choose MPC01 collection and Parameter name "PARAM01".

 

nr_02036_Untitled

Last but not least - connect white triangle from Timeline to "Set Vector Parameter Value" node. Triangles in blueprints are for updating events. They generally control the flow of the script, order of operations. You can save the script and drag and drop your blueprint to viewport. Without dragging it will not work.

 

monkey.gif

The result: after pressing "Play" our monkey changes roughness in 3 seconds intervals.

 

Author: Michal Franczak Editor: Michał Franczak
Tags:
You may also like...
Hum3D Car render challenge

Hum3D Car render challenge

Sixth annual Hum3D competition for the best Car render.
×

LEAVE A COMMENT

You need to be logged in to leave a comment. Don't have account? Register now.
  • ul. Przedzalniana 8, 15-688 Bialystok, POLAND