Materials¶
System · Materials · server and client scripts
Materials lists, reads, defines, and removes the surface materials of a place. A material sets how its parts look, collide, and sound. A material with a Shader draws its parts with a shader from the project's shaders folder; see Writing a material shader.
GetMaterials¶
GetMaterials returns an array of MaterialEntry tables with the asset id, name, pipeline, and surface model of every material in the place.
Example
GetMaterial¶
GetMaterial returns the MaterialSpec of a material by asset id or name, in the form DefineMaterial takes.
Example
Errors (1)
| Error | When |
|---|---|
no material '<idOrName>' |
No material has that asset id or name. |
DefineMaterial¶
DefineMaterial defines a material, or redefines the one with the same Id, and returns its asset id. Without a Name, the material gets the next free name. To add a material, pick an Id that no material in the place has. Studio numbers its ids upward from the lowest project id, so the highest ones, which the examples use, stay free.
Effects
- Passing
parent, a material asset id, sets the material RemoveMaterial moves surfaces to when no replacement is given. From the next server tick, the tablesspecleaves out (Emission,Studs,Water,Physics,Footsteps,Impacts, andShaderwith itsParams) come fromparent;Surface,PipelineandModelalways come fromspec. When the server cannot load a material file forparent, it logs an error and the material keeps only the tables inspec. - Updates the material's surfaces and their physics until the server stops. The project's
materialsfolder keeps its files; only Studio's material editor writes them.
Example
Errors (3)
| Error | When |
|---|---|
Pipeline must be 'Opaque', 'Cutout' or 'Transparent' for a material with a Shader, got '<Pipeline>' |
With a Shader, set Pipeline to "Opaque", "Cutout" or "Transparent", or leave it out for "Opaque". |
Materials.DefineMaterial: no shader file 'shaders/<Shader>.slang' in the project |
Set Shader to "toon" for shaders/toon.slang. |
DefineMaterial can only be called from the server |
Called from a client script. |
RemoveMaterial¶
RemoveMaterial removes a material and moves its surfaces to replacementIdOrName, or when that is omitted, to the material's parent or Plastic.
Effects
- Removes the material until the server stops. The project's
materialsfolder keeps its files.
Example
Errors (1)
| Error | When |
|---|---|
RemoveMaterial can only be called from the server |
Called from a client script. |
ReplaceMaterial¶
ReplaceMaterial moves every surface from one material to another and removes the first.
Example
Errors (1)
| Error | When |
|---|---|
ReplaceMaterial can only be called from the server |
Called from a client script. |
ReloadMaterial¶
ReloadMaterial reads a material file from the project's materials folder again and redefines the material with it. Its surfaces keep the material.
Example
Errors (2)
| Error | When |
|---|---|
the material does not reload: no-dir |
The server does not run from a project. |
ReloadMaterial can only be called from the server |
Called from a client script. |
SetParam¶
SetParam sets one field of a material's shader on the server; client scripts use Override for client-local parameter updates. Pass a number, Vector3 or Color, boolean, or texture asset id string that matches the field; see parameters.
Effects
Overridesends nothing over the network; the material file, the server, and other players keep the material'sParams. A shader that animates with time alone can read SurfaceInput.time instead.
Example
Errors (1)
| Error | When |
|---|---|
SetParam can only be called from the server |
Called from a client script. |
GetParam¶
GetParam returns the shared value of shader parameter field on material.
Example
Override¶
Override sets a client-local override for shader parameter field on material without changing the shared value.
Errors (1)
| Error | When |
|---|---|
Override can only be called from a client script |
Called from a server script. |
ClearOverride¶
ClearOverride removes a client-local override for shader parameter field on material.
Errors (1)
| Error | When |
|---|---|
ClearOverride can only be called from a client script |
Called from a server script. |
GetOverride¶
GetOverride returns the client-local override for shader parameter field on material, or nil when none is set.
Errors (1)
| Error | When |
|---|---|
GetOverride can only be called from a client script |
Called from a server script. |