MeshInstance3D
Entity that instances meshes into a scenario.
Entity that instances meshes into a scenario.
MeshInstance3D is a node that takes a Mesh resource and adds it to the current scenario by creating an instance of it. This is the class most often used to render 3D geometry and can be used to instance a single Mesh in many places. This allows reusing geometry, which can save on resources. When a Mesh has to be instantiated more than thousands of times at close proximity, consider using a MultiMesh in a MultiMeshInstance3D instead.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
MeshInstance3DConstructor
public MeshInstance3D();Properties3
SkeletonProperty
public EntityPath Skeleton { get; set; }EntityPath to the Skeleton3D associated with the instance.
Note: The default value of this property has changed in Reckfell. Enable ProjectSettings.animation/compatibility/default_parent_skeleton_in_mesh_instance_3d if the old behavior is needed for compatibility.
Methods22
BakeMeshFromCurrentBlendShapeMixArrayMesh
public ArrayMesh BakeMeshFromCurrentBlendShapeMix(ArrayMesh existing = null);Takes a snapshot from the current ArrayMesh with all blend shapes applied according to their current weights and bakes it to the provided existing mesh. If no existing mesh is provided a new ArrayMesh is created, baked and returned. Mesh surface materials are not copied.
Performance: Mesh data needs to be received from the GPU, stalling the RenderingServer in the process.
| Name | Type | Default |
|---|---|---|
existing | ArrayMesh | null |
ArrayMeshBakeMeshFromCurrentSkeletonPoseArrayMesh
public ArrayMesh BakeMeshFromCurrentSkeletonPose(ArrayMesh existing = null);Takes a snapshot of the current animated skeleton pose of the skinned mesh and bakes it to the provided existing mesh. If no existing mesh is provided a new ArrayMesh is created, baked, and returned. Requires a skeleton with a registered skin to work. Blendshapes are ignored. Mesh surface materials are not copied.
Performance: Mesh data needs to be retrieved from the GPU, stalling the RenderingServer in the process.
| Name | Type | Default |
|---|---|---|
existing | ArrayMesh | null |
ArrayMeshCreateConvexCollisionvoid
public void CreateConvexCollision(bool clean = true, bool simplify = false);This helper creates a StaticBody3D child node with a ConvexPolygonShape3D collision shape calculated from the mesh geometry. It's mainly used for testing.
If clean is true (default), duplicate and interior vertices are removed automatically. You can set it to false to make the process faster if not needed.
If simplify is true, the geometry can be further simplified to reduce the number of vertices. Disabled by default.
| Name | Type | Default |
|---|---|---|
clean | bool | true |
simplify | bool | false |
CreateDebugTangentsvoid
public void CreateDebugTangents();This helper creates a MeshInstance3D child node with gizmos at every vertex calculated from the mesh geometry. It's mainly used for testing.
CreateMultipleConvexCollisions2 overloads
public void CreateMultipleConvexCollisions();This helper creates a StaticBody3D child node with multiple ConvexPolygonShape3D collision shapes calculated from the mesh geometry via convex decomposition. The convex decomposition operation can be controlled with parameters from the optional settings.
public void CreateMultipleConvexCollisions(MeshConvexDecompositionSettings settings = null);This helper creates a StaticBody3D child node with multiple ConvexPolygonShape3D collision shapes calculated from the mesh geometry via convex decomposition. The convex decomposition operation can be controlled with parameters from the optional settings.
| Name | Type | Default |
|---|---|---|
settings | MeshConvexDecompositionSettings | null |
CreateTrimeshCollisionvoid
public void CreateTrimeshCollision();This helper creates a StaticBody3D child node with a ConcavePolygonShape3D collision shape calculated from the mesh geometry. It's mainly used for testing.
FindBlendShapeByNameint
public int FindBlendShapeByName(StringName name);Returns the index of the blend shape with the given name. Returns -1 if no blend shape with this name exists, including when MeshInstance3D.Mesh is null.
| Name | Type | Default |
|---|---|---|
name | StringName | — |
intGetActiveMaterialMaterial
public Material GetActiveMaterial(int surface);Selects the surface base material in order: instance MaterialOverride, surface override, then Mesh resource material. MaterialOverlay is an additional pass and is not included in this returned base material.
| Name | Type | Default |
|---|---|---|
surface | int | — |
surfaceExisting mesh surface index starting at 0, not an entity or GridMap item index.
MaterialSelected Material, or null if no suitable resource exists. This is a resource reference; multiple instances can share it.
GetBlendShapeCountint
public int GetBlendShapeCount();Returns the number of blend shapes available. Produces an error if MeshInstance3D.Mesh is null.
intGetBlendShapeValuefloat
public float GetBlendShapeValue(int blendShapeIdx);Returns the value of the blend shape at the given blend_shape_idx. Returns 0.0 and produces an error if MeshInstance3D.Mesh is null or doesn't have a blend shape at that index.
| Name | Type | Default |
|---|---|---|
blendShapeIdx | int | — |
floatGetMeshMesh
public Mesh GetMesh();MeshGetSkeletonPathEntityPath
public EntityPath GetSkeletonPath();EntityPathGetSkinSkin
public Skin GetSkin();SkinGetSkinReferenceSkinReference
public SkinReference GetSkinReference();Returns the internal SkinReference containing the skeleton's Rid attached to this RID. See also Resource.GetRid, SkinReference.GetSkeleton, and RenderingServer.InstanceAttachSkeleton.
SkinReferenceGetSurfaceOverrideMaterialMaterial
public Material GetSurfaceOverrideMaterial(int surface);Returns the stored surface override for this instance, not the Mesh material or necessarily the active base material. Object MaterialOverride takes priority; use GetActiveMaterial to resolve base-material priority.
| Name | Type | Default |
|---|---|---|
surface | int | — |
surfaceExisting surface-slot index starting at zero.
MaterialAssigned override Material, or null even when the Mesh resource has a material.
GetSurfaceOverrideMaterialCountint
public int GetSurfaceOverrideMaterialCount();Number of override slots corresponding to Mesh surfaces, not the count of assigned materials. One surface with a null override still returns 1.
intNumber of surface override slots.
SetBlendShapeValuevoid
public void SetBlendShapeValue(int blendShapeIdx, float value);Sets the value of the blend shape at blend_shape_idx to value. Produces an error if MeshInstance3D.Mesh is null or doesn't have a blend shape at that index.
| Name | Type | Default |
|---|---|---|
blendShapeIdx | int | — |
value | float | — |
SetMeshvoid
public void SetMesh(Mesh mesh);| Name | Type | Default |
|---|---|---|
mesh | Mesh | — |
SetSkeletonPathvoid
public void SetSkeletonPath(EntityPath skeletonPath);| Name | Type | Default |
|---|---|---|
skeletonPath | EntityPath | — |
SetSkinvoid
public void SetSkin(Skin skin);| Name | Type | Default |
|---|---|---|
skin | Skin | — |
SetSurfaceOverrideMaterialvoid
public void SetSurfaceOverrideMaterial(int surface, Material material);Overrides one surface on this instance without changing the source Mesh. Instance MaterialOverride takes precedence. Pass null to clear the surface override.
| Name | Type | Default |
|---|---|---|
surface | int | — |
material | Material | — |
surfaceExisting surface index starting at 0.
materialMaterial resource or null. Assignment does not create a unique copy; duplicate the material before independent editing.