Jump to content

(Unity SDK) Hide controller model at runtime


cmdr2

Recommended Posts

Hi,

 

I'm looking for a way to hide the controller model at runtime, since I need to show the controller only during parts of the game. I'm using the Unity SDK.

 

Presently what works for me (but I'm not sure if this is the correct, future-proof way):

 

1. Store the Controller's GameObject provided by the CONTROLLER_MODEL_LOADED event: WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.CONTROLLER_MODEL_LOADED, onControllerLoadedEvent);

2. Keep setting that controllerGameObject.SetActive to false in an Update(), since it seems to become active a few frames after the event callback above.

 

I verified that the controller's orientation data continues to be reported correctly, even when the controller's gameObject is hidden.

 

I was curious to know if there's a better way to do this.

 

Thanks!

~cmdr2

Link to comment
Share on other sites

Hi ,

 

Yes, this is a correct way and easiest way.

We also provide alternative way for your reference.

 

Assuming listening to CONTROLLER_MODEL_LOADED :

 

 

    void OnEnable()    {        WaveVR_Utils.Event.Listen (WaveVR_Utils.Event.CONTROLLER_MODEL_LOADED, OnControllerLoaded);    }     // In SDK 2.1.8    private GameObject loadedController_R = null, loadedController_L;    void OnControllerLoaded(params object[] args)    {        WVR_DeviceType _type = (WVR_DeviceType)args [0];        if (_type == WVR_DeviceType.WVR_DeviceType_Controller_Right)            this.loadedController_R = (GameObject)args [1];        if (_type == WVR_DeviceType.WVR_DeviceType_Controller_Left)            this.loadedController_L = (GameObject)args [1];    }

 

 

Then you can call ShowControllerModels (bool) to show / hide controller models.

 

    // True to show, false to hide controller models.    private void ShowControllerModels(bool show)    {        int _children_count =  this.loadedController_R.transform.childCount;        for (int i = 0; i < _children_count; i++)        {            this.loadedController_R.transform.GetChild (i).gameObject.SetActive (show);        }        _children_count =  this.loadedController_L.transform.childCount;        for (int i = 0; i < _children_count; i++)        {            this.loadedController_L.transform.GetChild (i).gameObject.SetActive (show);        }    }

 Hope this is helpful.

Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...