Version:

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

[getmaterialvariablenode, variablematerial, materialvariable]

Inputs


PinTypeDescription
InEventTriggers the node.

Outputs


PinTypeDescription
OutEventSends when the node is finished.
MaterialMaterialSends the variable’s current material.

Set Material Variable Node

[setmaterialvariablenode, variablematerial, materialvariable]

Inputs


PinTypeDescription
InEventTriggers the node.
MaterialMaterialSets the variable’s current material.

Outputs


PinTypeDescription
OutEventSends when the node is finished.

Material Variable Node Example

The following example uses a material variable node to make a material flash red.

  1. The Variable Manager defines a variable material node named MyMaterial.

  2. 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.

  3. 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 Script Canvas editor script that uses the variable material node.]

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.

[Example Script Canvas editor script that uses the variable material node to change the color of the object]