Garry's Mod Wiki

Material:SetMaterial

  Material:SetMaterial( string matname )

Description

Sets the material used by the panel.

If the material is not showing up as the correct size, try setting the Material panel's AutoSize variable to false

Arguments

1 string matname
The file path of the material to set (relative to "garrysmod/materials/").

Example

Creates a Material panel and sets the material to a screen space effect.

-- Black background panel BGPanel = vgui.Create("DPanel") BGPanel:SetSize(200, 200) BGPanel:Center() BGPanel:SetBackgroundColor(Color(0, 0, 0, 255)) local mat = vgui.Create("Material", BGPanel) mat:SetPos(5, 5) mat:SetSize(190, 190) -- It's not really good to use a models material for VGUI drawing -- But it looks good enough for a quick demo mat:SetMaterial("models/screenspace") -- Stretch to fit mat.AutoSize = false
Output: