Hiding SteamVR Vive controller models?
Hi! Using SteamVR with the Vive, a default controller model appears, but I've put a hand in the controller tree. How would one know hide the controller model that SteamVR adds automatically? Thanks!
Answer by Rib · Jun 01, 2016 at 12:51 AM
Hi, I just faced the same issue and found a few other approaches...
In my case I have a script that's not attached directly to a controller - though I've looked up the controller game objects.
One approach I found for hiding/showing all controllers (but I'm not sure if it's really intended to be used from non-SteamVR scripts) is to send a "hide_render_models" message like this:
 SteamVR_Utils.Event.Send("hide_render_models", !visible);
 
               Another approach I tried was to [de]activate the SteamVR_RenderModel but found that I couldn't reactivate a model for some reason...
 void SetControllerVisible(GameObject controller, bool visible)
 {
     foreach (SteamVR_RenderModel model in controller.GetComponentsInChildren<SteamVR_RenderModel>())
         model.gameObject.SetActive(visible);
 }
 
               (Maybe if you just want to hide the models though, something like that might be ok)
Looking at the SteamVR_RenderModel.cs code that handles the hide_render_models message, I ended up with a function like this for hiding/showing specific controllers:
 void SetControllerVisible(GameObject controller, bool visible)
 {
     foreach (SteamVR_RenderModel model in controller.GetComponentsInChildren<SteamVR_RenderModel>())
     {
         foreach (var child in model.GetComponentsInChildren<MeshRenderer>())
             child.enabled = visible;
     }
 }
 
              Thanks, the last one worked nicely here when applied to the parent of a script attached to the controller! Similary to the surface hider, I still have to invoke a call to it every now and then for the $$anonymous$$i dot to not appear when the thumb starts moving over the thumb pad.
Answer by JPhilipp · Apr 27, 2016 at 03:11 PM
Update: This may be totally not how it's done, but achieved the required hiding when attached to the Update() of a script attached to the Controller gameObject.
 void HideDefaultControllerIfNeeded() {
     if (!didHideDefaultController) {
         Renderer[] renderers = this.transform.parent.GetComponentsInChildren<Renderer>();
         for (int i = 0; i < renderers.Length; i++) {
             if (renderers[i].material.name == "Standard (Instance)") {
                 renderers[i].enabled = false;
                 didHideDefaultController = true;
             }
         }
     }
 }
 
              Answer by Mmmpies · May 24, 2016 at 06:25 PM
Ah I see you managed to work out how to hide it all. I had a play and you can hide and show the controllers with identical code:
 using UnityEngine;
 using System.Collections;
 
 public class hideController : MonoBehaviour {
 
     private bool Hidden = false;
 
     public void HideController()
     {
         Renderer[] renderers = this.transform.parent.GetComponentsInChildren<Renderer>();
         for (int i = 0; i < renderers.Length; i++) 
         {
             if (renderers[i].material.name == "Standard (Instance)") 
             {
                 renderers[i].enabled = Hidden;
             }
         }
         Hidden = !Hidden;
     }
 }
 
               From another script that's also attached to the controller I source that script file in Start.
     private hideController myHC;
 
 // Then in Start ...
 
     void Start()
     {
         myHC = gameObject.GetComponent<hideController> ();
     }
 
 // And call the code when the trigger gets pressed (just an example)
 
         if (device.GetPressDown (SteamVR_Controller.ButtonMask.Trigger)) {
             myHC.HideController ();
         }
 
               The bool can only be true or false so the line
Hidden = !Hidden;
Switches between true and false.
Answer by Shii · May 12, 2021 at 01:27 PM
You can also make an array of all render models somewhere and call this:
 foreach (SteamVR_RenderModel renderModel in renderModels)
                 renderModel.SetMeshRendererState(false);
 
              Your answer