Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

Mesh.GetTopology

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Declaration

public MeshTopology GetTopology(int submesh);

Parameters

Parameter Description
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

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

Description

Retrieves the topology type of the specified submesh in the Mesh.

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 submesh public 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, SetIndices function.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961