Please Select Your Location
Australia
Österreich
België
Canada
Canada - Français
中国
Česká republika
Denmark
Deutschland
France
HongKong
Iceland
Ireland
Italia
日本
Korea
Latvija
Lietuva
Lëtzebuerg
Malta
المملكة العربية السعودية (Arabic)
Nederland
New Zealand
Norge
Polska
Portugal
Russia
Saudi Arabia
Southeast Asia
España
Suisse
Suomi
Sverige
台灣
Ukraine
United Kingdom
United States
Please Select Your Location
België
Česká republika
Denmark
Iceland
Ireland
Italia
Latvija
Lietuva
Lëtzebuerg
Malta
Nederland
Norge
Polska
Portugal
España
Suisse
Suomi
Sverige

How do I get controller objects in runtime?

WaveVR uses the Controller Loader to load the controller in runtime. Therefore, controller objects cannot be modified in Editor.

In Assets > WaveVR > Extra > GenericModel > Resources > Controller, the Generic Controller Model prefabs shows the structure of a WaveVR controller.

The prefab contains the Controller Model, Controller Beam, and Controller Pointer.

Go to Find the Beam and Pointer in the controller model (sample code) to learn how to get the Beam and Pointer.

Find the Beam and Pointer in the controller model (sample code)

Follow the steps below to find the Beam and Pointer.
  1. Listen to the CONTROLLER_MODEL_LOADED broadcast to receive the controller instance.
  2. Find all the children of the controller.
  3. Find GameObject with beam/pointer in the children.
    private GameObject dominantController = null, nonDominantController = null;
    void OnEnable()
    {
        WaveVR_Utils.Event.Listen (WaveVR_Utils.Event.CONTROLLER_MODEL_LOADED, OnControllerLoaded);
    }
    
    void OnControllerLoaded(params object[] args)
    {
        WaveVR_Controller.EDeviceType _type = (WaveVR_Controller.EDeviceType)args [0];
        if (_type == WaveVR_Controller.EDeviceType.Dominant)
        {
            this.dominantController = (GameObject)args [1];
            listControllerObjects(this.dominantController);
        }
        if (_type == WaveVR_Controller.EDeviceType.NonDominant)
        {
            this.nonDominantController = (GameObject)args [1];
            listControllerObjects(this.nonDominantController);
        }
    }
    
    void OnDisable()
    {
        WaveVR_Utils.Event.Remove (WaveVR_Utils.Event.CONTROLLER_MODEL_LOADED, OnControllerLoaded);
    }
    
    private void listControllerObjects(GameObject ctrlr)
    {
        if (ctrlr == null)
            return;
    
        WaveVR_Beam _beam = null;
        WaveVR_ControllerPointer _pointer = null;
    
        // Get all children.
        GameObject[] _objects = new GameObject[ctrlr.transform.childCount];
        for (int i = 0; i < ctrlr.transform.childCount; i++)
            _objects[i] = ctrlr.transform.GetChild (i).gameObject;
    
        // Find beam.
        for (int i = 0; i < _objects.Length; i++)
        {
            _beam = _objects [i].GetComponentInChildren<WaveVR_Beam> ();
            if (_beam != null)
                break;
        }
        if (_beam != null)
            Debug.Log ("‍Find beam: "‍ + _beam.name);
    
        // Find pointer.
        for (int i = 0; i < _objects.Length; i++)
        {
            _pointer = _objects [i].GetComponentInChildren<WaveVR_ControllerPointer> ();
            if (_pointer != null)
                break;
        }
        if (_pointer != null)
            Debug.Log ("‍Find pointer: "‍ + _pointer.name);
    }
Submit
Thank you! Your feedback helps others to see the most helpful information.