CanvasRenderer.SetColor() does not apply color updates to Polyspatial Renderers

We are attempting to port an existing project to VisionOS MR.

A lot of our UI uses button states to determine a graphic’s color, including the Normal state color.

This presents an issue as deep down in the graphic’s class when the ColorTween is finshed it attempts to set the color via CanvasRenderer.SetColor().

This does not apply any changes to the MaskingShader material on the Polyspatial UI Renderer objects

Currently we overwrite DoStateTransition to apply the color state to the graphics.color and that works OK. Just wanted to flag this as an issue

Is this with 1.0.3? I tested a Canvas with Image and Text (TMP) children with the following script, and got the random colors I expected:

using UnityEngine;

public class SetColor : MonoBehaviour
{
    // Update is called once per frame
    void Update()
    {
        foreach (var canvasRenderer in GetComponentsInChildren<CanvasRenderer>())
        {
            canvasRenderer.SetColor(Random.ColorHSV());
        }
    }
}

We also test with the standard Button Transition: Color Tint and different colors for Normal Color/Pressed Color/etc.

We’re changing the way we apply the color (as part of adding support for custom materials/shaders on UI elements), but if you submit a repro case and let us know the incident number (IN-#####), we can take a look. Up to you, though, since you’ve already found a workaround.

We are on 1.0.3 and I can see the mistake I made.

We have embedded the polyspatial package to make custom alterations to the MaskingShader that are not yet supported (dynamic colors, vertex colors). I was no longer using the color.a value for alpha so re-applying that has fixed some of our button states!

Some notes for FYI:

  • It would be great to have the MaskingShader support VertexColors by default
  • CanvasRenderer.SetColor() definetely does not update the vertex color streams of the PolyspatialRenderer
  • The Vertex colors would need to follow the correct Color Space of the project/Canvas if so (Gamma / Linear)

Sure, that seems like something we could add pretty easily (although, as I mentioned, we’re adding the ability to set custom materials/shaders on UI elements, which would give you the ability to use a different shader without having to embed the package).

Right; we set the color as a material property (_Color), rather than in the vertex data.

We generally don’t support gamma color space (because there are many, many different places like this where it becomes an issue), so even if we allowed for it in this particular case, I would not recommend using it.