Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetTopology(int)

Retrieves the topology type of the specified submesh in the Mesh.
Read time 1 minuteLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public MeshTopology GetTopology(int submesh)

Parameters

submesh

The index of the submesh whose topology you want to retrieve. Submesh indices are zero-based, and the maximum index is Mesh.subMeshCount - 1.

Returns

Type

Description

MeshTopologyReturns the topology type of the specified submesh, as defined in the MeshTopology enum. This value indicates how the submesh's vertices are connected.

Remarks

The topology specifies the geometric arrangement of vertices in a submesh and is determined when you assign data using the Mesh.SetIndices method. Common topology types include MeshTopology.Triangles, MeshTopology.Lines, and MeshTopology.Points, as defined in the MeshTopology enum.
This method allows you to inspect the topology of a submesh at runtime, which can be helpful for debugging or procedural mesh generation. Ensure that the submesh index is within the valid range (0 ≤ submesh < Mesh.subMeshCount) to avoid errors.
If no data has been assigned to the submesh, the default topology is MeshTopology.Triangles.
using UnityEngine;// Example that checks the topology of a submeshpublic class MeshTopologyExample : MonoBehaviour{ void Start() { // Get the MeshFilter attached to this GameObject Mesh mesh = GetComponent<MeshFilter>().sharedMesh; // Iterate through submeshes and print their topology for (int submesh = 0; submesh < mesh.subMeshCount; submesh++) { MeshTopology topology = mesh.GetTopology(submesh); Debug.Log($"Submesh {submesh}: Topology = {topology}"); } }}
Additional Resources: MeshTopology enum, Mesh.SetIndices function.