IN THIS ARTICLE
Material Variables
Material Variables
When you use a node such as Find by Name, Load by Name, or Clone, the script can only use the material for that one frame. After the frame, the material is then invalid. If you want to reuse the material in your script, you can store the material in a Variable Material node. You can also use this node when you want to find or load a material only once when the game starts.
For more information about creating variable nodes, see Managing Script Canvas Variables.
Note
To use a material variable node, you must assign the variable to a valid material with a node such as Find by Name, Load by Name, or Clone.
Contents
Get Material Variable Node
Inputs
Pin | Type | Description |
---|---|---|
In | Event | Triggers the node. |
Outputs
Pin | Type | Description |
---|---|---|
Out | Event | Sends when the node is finished. |
Material | Material | Sends the variable’s current material. |
Set Material Variable Node
Inputs
Pin | Type | Description |
---|---|---|
In | Event | Triggers the node. |
Material | Material | Sets the variable’s current material. |
Outputs
Pin | Type | Description |
---|---|---|
Out | Event | Sends when the node is finished. |
Material Variable Node Example
The following example uses a material variable node to make a material flash red.
The Variable Manager defines a variable material node named MyMaterial.
The Load by Name node specifies the
materials/gettingstartedmaterials/grid
material file and the result of the node is stored in a variable with a Set MyMaterial node.Every 0.5 seconds, the Get MyMaterial node uses the variable with the Set Param Color node to change the material’s diffuse parameter from red to white.
Example
One entity has the primitive_cylinder.cfg
mesh and the other entity has the primitive_sphere.cfg
mesh. Both entities share the same grid.mtl
material file. When the Script Canvas graph runs, it changes the appearance of every entity that has this material applied.