- Home /
Why doesn't UIVertex.uv2 work?
I was happy to see unity 2017 has a uv2 and uv3 channel, both in the canvas channel settings and in the UIVertex class, but these don't seem to actually work. They always seem to have zero values in the shader. Are they just a big tease or am I missing some way to make these channels work with ui shaders?
I have same issue.
Does anyone know this problem?
I had already set Canvas.additionalShaderChannels to Everything.
I have same issue too. in unity 5.6.6
And It is effective in unity 2018.2.0.
Answer by Jon-Manning · Jan 12, 2019 at 05:29 AM
The second UV set in a UIVertex is actually uv1
, not uv2
. The first set is uv0
. Are you trying to work with the third UV set (which is called uv2
) by mistake?
Answer by quizcanners · Feb 01, 2019 at 03:36 PM
Found the reason, I think:
Description to AddVertex function is as such:
// Summary:
// Add a single vertex to the stream.
//
// Parameters:
// position:
//
// color:
//
// uv0:
//
// uv1:
//
// normal:
//
// tangent:
//
// v:
public void AddVert(UIVertex v);
So even though UIVertex contains uv2,3 (3rd and 4th set), the function itself isn't reading them. We need to use the other one I believe:
AddVert(Vector3 position, Color32 color, Vector2 uv0, Vector2 uv1, Vector2 uv2, Vector2 uv3, Vector3 normal, Vector4 tangent);
I plan to test it soon.
[Update]
Yep, this extension function did the trick:
public static void AddFull(this VertexHelper vh, UIVertex vert) => vh.AddVert(vert.position, vert.color, vert.uv0, vert.uv1, vert.uv2, vert.uv3, vert.normal, vert.tangent);
I can't find this function vh.AddVert(vert.position, vert.color, vert.uv0, vert.uv1, vert.uv2, vert.uv3, vert.normal, vert.tangent);
Put this code anywhere:
public static class YourUiExtensions
{
public static void AddFull(this VertexHelper vh, UIVertex vert) =>
#if UNITY_2019_1_OR_NEWER
vh.AddVert(vert.position, vert.color, vert.uv0, vert.uv1, vert.uv2, vert.uv3, vert.normal, vert.tangent);
#else
vh.AddVert(vert.position, vert.color, vert.uv0, vert.uv1, vert.normal, vert.tangent);
#endif
}
And you need:
using UnityEngine.UI;