S&box Wiki

Material Attributes

What Are Material Attributes

Material attributes are an easy way to put custom data into a material, they consist of a name and a value.

How To Define a Material Attribute

  1. First, locate the Attributes tab.

Attributes Tab

  1. The section highlighted below is where you can add, edit, and remove Attributes.

User Material Attributes

  1. To add a new value, click the plus button at the bottom. Double click on the name or value fields to edit them. To remove a value, click the X button.

Adding Attributes

Using Attributes

After giving your material an attribute, it can be referenced through code. The Example below shows how to change the material of the citizen model's skin in real time.

The skin material for the citizen has a material attribute named Skin with the value set to 1

Skin Attribute

public class Example : AnimatedEntity { public override void Spawn() { base.Spawn(); SetModel( "models/citizen/citizen.vmdl" ); Material darkerSkin = Material.Load("models/citizen/skin/citizen_skin03.vmat_c") // This overrides all materials on the citizen model with the material attribute "skin" this.SetMaterialOverride(darkerSkin, "skin" ); } }