S&box Wiki

Revision Difference

material_attributes#548981

<cat>Material.Intro</cat>⤶ <title>Material Attributes</title>⤶ ⤶ # What are they?⤶ ⤶ Material attributes just are a basic way to put random values 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](https://i.imgur.com/SKGpItp.png)⤶ ⤶ 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](https://i.imgur.com/cdCspU5.png)⤶ ⤶ 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](https://i.imgur.com/kRPZzg2.gif)⤶ ⤶ and here is an example of multiple, as long as the name contains no spaces you can put what you want!⤶ ⤶ ![Multiple Attributes](https://i.imgur.com/ASPsTlL.png)⤶ ⤶ # 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 overrided in game.⤶ ⤶ What this is useful for is if your model has 2 or more 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!⤶ ⤶ <warning> for this to work in code, the value must be set to 1 </warning>⤶ ⤶ Like so.⤶ ⤶ ![Skin Attribute](https://i.imgur.com/FGmwhr3.png)⤶ ⤶ 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⤶ }⤶ ⤶ }⤶ ```⤶ ⤶