S&box Wiki

Log in to edit

Material Attributes

<cat>Material.Intro</cat> <title>Material Attributes</title> # 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](https://i.imgur.com/SKGpItp.png) 2) The section highlighted below is where you can add, edit, and remove Attributes. ![User Material Attributes](https://i.imgur.com/cdCspU5.png) 3) 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](https://i.imgur.com/kRPZzg2.gif) # 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](https://i.imgur.com/FGmwhr3.png) ``` 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" ); } } ```