StaticMesh is a static CoreMesh. StaticMeshes can be placed in the scene and (if networked or client-only) moved at runtime, but the mesh itself cannot be animated.
See AnimatedMesh for meshes with animations.
|Property Name||Return Type||Description||Tags|
| || ||If ||Read-Write, Client-Only|
|Function Name||Return Type||Description||Tags|
| || ||Set the material in the given slot to the material specified by assetId.||None|
| || ||Get the MaterialSlot object for the given slot. If called on the client on a networked object, the resulting object cannot be modified.||None|
| || ||Get an array of all MaterialSlots on this mesh. If called on the client on a networked object, the resulting object cannot be modified.||None|
| || ||Resets a material slot to its original state.||None|
| || ||Returns a ||None|
In this example, the
slotName property of all material slots belonging to the CUBE will be printed to the event log.
local CUBE = script.parent -- Get an array of material slots local MaterialSlots = CUBE:GetMaterialSlots() -- Print the names of all material slots belonging to the "CUBE" for index, materialSlot in ipairs(MaterialSlots) do print(materialSlot.slotName) end
See also: MaterialSlot.slotName
In this example a cube's material is changed at runtime. The script is placed as a child of the cube object and the desired material is assigned to the script as a custom property.
local CUBE = script.parent local MATERIAL = script:GetCustomProperty("Material") local matSlot = CUBE:GetMaterialSlots() CUBE:SetMaterialForSlot(MATERIAL, matSlot.slotName)
The debris physics simulation is a client-only feature. The exact movement of simulated meshes is not expected to be the same across clients and should be used for visual effects, not for determining gameplay outcomes.
The following example takes several Static Meshes and explodes them randomly away from the epicenter. As written, it modifies only meshes that are children of the script object. When the player approaches the script at 3 meters or less then the function ExplodeChildren() is called, enabling the property
isSimulatingDebrisPhysics for all the children, in addition to an impulse vector.
local DISTANCE_TO_EXPLODE = 300 local EXPLOSION_FORCE = 450 local hasExploded = false function ExplodeChildren() local rng = RandomStream.New() local epicenter = script:GetWorldPosition() for _, child in ipairs(script:GetChildren()) do -- Enable client physics child.isSimulatingDebrisPhysics = true -- Impulse vector local direction = (child:GetWorldPosition() - epicenter):GetNormalized() child:SetVelocity((rng:GetVector3() + direction * 2) * EXPLOSION_FORCE) end end function Tick() -- Call the explosion function only once if hasExploded then return end -- Detect if the local player has gotten close to the objects local player = Game.GetLocalPlayer() local distance = (player:GetWorldPosition() - script:GetWorldPosition()).size if distance < DISTANCE_TO_EXPLODE then hasExploded = true ExplodeChildren() end end