S&box Wiki

Material Attributes

What are they?

Material attributes just are a basic way to put custom data into a material, they consist of a name and any value you want really.

How to define a Material Attribute

So to define a Material Attribute you can do it as so. First open your material, and locate the Attributes tab.

Attributes Tab

Inside this tab you will see this big region, this is where all your material attributes are contained, and where you add or remove them!

User Material Attributes

So now you can add an attribute like so, and here is how you can name it and define the value! (note any value can be put here really!)

Adding Attributes

and here is an example of multiple, as long as the name contains no spaces you can put what you want!

Multiple Attributes

Using Attributes to Override specific materials in code!

Currently the only main thing you can do with these attributes are to make it so only the material with the attribute set can be overridden in game.

What this is useful for is, if your model has multiple materials, but you only want to replace 1 specific material at runtime (without material groups), you can use attributes to specify to only override this specific material!

What I mean by this is, for example, the citizen skin!

For this to work in code, the value must be set to 1

Like so.

Skin Attribute

Now what they do with this is they do something along the lines of this

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"); // here we just grab any material this.SetMaterialOverride(darkerSkin, "skin" ); // this method is used to override materials in the model // however the 2nd value given the method, will check all the models materials // and only override the materials that have a "skin" attribute with the value set to 1 } }