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!

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;
    }
}

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*.material.name == "Standard (Instance)") {*

renderers*.enabled = false;*
didHideDefaultController = true;
}
}
}
}

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*.material.name == "Standard (Instance)")* 
  •  	{*
    

_ renderers*.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 ();*
* }*

// 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.

You can also make an array of all render models somewhere and call this:

foreach (SteamVR_RenderModel renderModel in renderModels)
                renderModel.SetMeshRendererState(false);