# engineSetElementMaterial (Client)

> Replaces the chosen materials of a single vehicle, ped or object with a material.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Materials and shaders
- **URL**: https://wiki.mymp.gg/en/engineSetElementMaterial

## Syntax

```lua
bool engineSetElementMaterial(element element, int|string selector, material material [, int priority = 0])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | A vehicle, ped, player or object. |
| `selector` | `int\|string` | Which material: its index from 1 or its name, as `engineGetModelMaterials` lists them. The name ignores case and takes the `*` and `?` wildcards. |
| `material` | `material` | The material drawn in their place. |
| `priority` | `int` | When several resources pick the same material, the highest priority wins; between equals, the newest. *(default: `0`)* |

## Returns

`true` when it was applied.

It applies over what the model already draws, materials set with `engineSetModelMaterial` included. It holds while the element lives, streamed in or out.

## Example

```lua
local gold = engineCreateMaterial("surface")
engineSetMaterialValue(gold, "metallicFactor", 1)

addCommandHandler("gold", function()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if vehicle then
        engineSetElementMaterial(vehicle, 1, gold)
    end
end)
```

### Note

An element that is not a vehicle, ped, player or object is an error.

## See also

- [engineRestoreElementMaterial (Client)](https://wiki.mymp.gg/en/engineRestoreElementMaterial.md): Undoes what this resource's engineSetElementMaterial did of a single vehicle, ped or object.
- [engineSetModelMaterial (Client)](https://wiki.mymp.gg/en/engineSetModelMaterial.md): Replaces the chosen materials of every instance of a model with a material.
- [engineSetElementTexture (Client)](https://wiki.mymp.gg/en/engineSetElementTexture.md): Swaps a texture on one vehicle, ped, player or object alone. Other instances of the same model keep their textures.
- [engineCreateMaterial (Client)](https://wiki.mymp.gg/en/engineCreateMaterial.md): Creates a material: a shader with parameter values, which then replaces or overlays the materials of models.
