cancel
Showing results for 
Search instead for 
Did you mean: 

Change Hand Color During Gameplay? UpdateAvatarMaterial

ResDig3
Honored Guest
I'm a super n00b building my first VR app using Unity 2017. Apologies if I'm missing something obvious or lacking a basic skill to solve my problem! But any help would be greatly appreciated!

I'm working on a scene that uses Touch controllers and Local Avatar & OVR Avatar Hand -- it's a simple first person scene in which the player can see her hands, control them with the Touch controllers, and interact with some objects in the scene. I'd like to be able to trigger changes to the hand color during play. Can't figure out how.

So far I've been able to change the hand color by editing 

UpdateAvatarMaterial, which is in OvrAvatarRenderComponent.cs. I changed mat.SetColor to a hard-coded color (in this case, blue). You can see where I commented out the original line and then added my change:  

protected void UpdateAvatarMaterial(Material mat, ovrAvatarMaterialState matState)

    {
        // Only update the material if it's a material we actively created
        ovrAvatarMaterialState cachedState;

        if (!materialStates.TryGetValue(mat, out cachedState))
        {
            return;
        }

        if (cachedState.Equals(matState))
        {
            return;
        }

     //   mat.SetColor("_BaseColor", matState.baseColor);
        mat.SetColor ("_BaseColor", Color.blue);



What I don't know how to do is use mat.SetColor  from a different script. Like, if the hand collides with a snow bank, detect the collision and change the hand color. I'm of course happy to go about this an entirely different way if somebody has a good idea.

Thanks!


1 REPLY 1

MikeF
Trustee
What i've done in the past is to set a public bool in the OVR script called "OverrideMaterial" with a return flag at the top of the material update method when it's true. Whenever i want to change some aspect of the material or swap it entirely, set that bool to true through whatever script you want, then you can change your properties or material without the OVR script reverting your changes since it updates every frame.