Search code examples
unity-game-engineaugmented-realityhololensmrtk

HoloLens - Unity: How to change color of cursor?


I tried to change the color via script on runtime of the cursor and it worked to 75%:

enter image description here

Mesh_top is the only part that does not change the color and I dont know why. All 4 parts use the same material, named "cursormaterial". What I tried:

  1. Changing the color by referencing to cursormaterial
  2. Changing the color by getting the component SkinnedMeshRenderer
  3. Trying to use ProptertyBlock


In all three cases I got the same result. The only thing that works is before hitting play I can change the color, this will change the color of the whole cursor. Changing it on runtime works only for 3 of 4 parts...´

--Edit--

    public SkinnedMeshRenderer cursorRendererOne, cursorRendererTwo, cursorRendererThree, cursorRendererFour;
private MaterialPropertyBlock _propBlock;
public Material material;

void Start()
{
    _propBlock = new MaterialPropertyBlock();
}

public void OnInputDown(InputEventData eventData)
{
    if (!isActivated)
    {
        //#1
        material.color = Color.blue;
        //#2
        cursorRendererOne.sharedMaterial.color = Color.blue;
        //#3
        cursorRendererOne.GetPropertyBlock(_propBlock);
        _propBlock.SetColor("_Color", Color.blue);
        cursorRendererOne.SetPropertyBlock(_propBlock);
        cursorRendererTwo.SetPropertyBlock(_propBlock);
        cursorRendererThree.SetPropertyBlock(_propBlock);
        cursorRendererFour.SetPropertyBlock(_propBlock);
        isActivated = true;
    }


Here u see the changed material, but the mesh_top looks but different: enter image description here
enter image description here


Solution

  • This is a "Bug" (maybe an intended one?).

    Open the Animation window (CTRL + 6)

    And in the hierachy select the CursorVisual

    If you now go to the animation called CursorWaitingAnim you can see there is a keyframe for the top_mesh color.

    enter image description here

    This single keyframe causes that the color of that tile can not be changed on runtime. The reason is that the animator runs after OnInputDown so it reverts the changes for any keyframed property.

    So if you don't need the Waiting animation simply remove that keyframe.

    enter image description here

    => you can manipulate the color at runtime again!


    Alternatively you could replace it by a one that instead of fixing the color simply disables the SkinnedMeshRenderer instead which basically has more or less the same effect but doesn't screw the colors:

    enter image description here