Select your preferred scripting language. All code snippets will be displayed in this language.
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.
Closem | Mesh to populate with UI data. |
Callback function when a UI element needs to generate vertices.
Used by Text, Image, and RawImage for example to generate vertices specific to their use case.
OnPopulateMesh is new in Unity 5.2. To upgrade code from Unity 5.1 or earlier and still using the now obsolete OnFillVBO, you can use the following glue code:
#pragma strict import System.Collections.Generic; import UnityEngine.UI;
@ExecuteInEditMode function _OnFillVBO(vbo: List.<UIVertex>) { /* (5.1 code) */ }
function OnPopulateMesh(m: Mesh) { var vbo = new List.<UIVertex>(); _OnFillVBO(vbo); var vh = new VertexHelper();
var quad = new UIVertex[4]; for (var i: int = 0; i < vbo.Count; i += 4) { vbo.CopyTo(i, quad, 0, 4); vh.AddUIVertexQuad(quad); } vh.FillMesh(m); }
using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
[ExecuteInEditMode] public class ExampleClass : Graphic { protected void _OnFillVBO(List<UIVertex> vbo) { /* (5.1 code) */ }
protected override void OnPopulateMesh(Mesh m) { var vbo = new List<UIVertex>(); _OnFillVBO(vbo);
using (var vh = new VertexHelper()) { var quad = new UIVertex[4]; for (int i = 0; i < vbo.Count; i += 4) { vbo.CopyTo(i, quad, 0, 4); vh.AddUIVertexQuad(quad); } vh.FillMesh(m); } } }