Search Unity

The name OVRInput does not exist in the current context

Discussion in 'AR/VR (XR) Discussion' started by omacha, Aug 24, 2017.

  1. omacha

    omacha

    Joined:
    Aug 21, 2017
    Posts:
    9
    Hello,

    I am currently developing a Unity application for Samsung Gear VR and I recently imported the Oculus Utilities into my project (I started a new project to test it out) to be able to support the Gear VR Controller.

    I am now faced with the strangest thing I've never experienced before, one of my script does not recognize OVRInput :
    The problem occurs on line 92 from this script (I've removed other code from this for readability).

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.VR;
    4. using UnityStandardAssets.CrossPlatformInput;
    5. using UnityStandardAssets.Utility;
    6. using Random = UnityEngine.Random;
    7.  
    8. namespace UnityStandardAssets.Characters.FirstPerson {
    9.  
    10.     [RequireComponent(typeof(CharacterController))]
    11.     [RequireComponent(typeof(AudioSource))]
    12.     public class FirstPersonController : MonoBehaviour {
    13.      
    14.         [SerializeField]
    15.         private bool m_IsWalking;
    16.         [SerializeField]
    17.         private float m_WalkSpeed;
    18.         [SerializeField]
    19.         private float m_RunSpeed;
    20.         [SerializeField]
    21.         [Range(0f, 1f)]
    22.         private float m_RunstepLenghten;
    23.         [SerializeField]
    24.         private float m_JumpSpeed;
    25.         [SerializeField]
    26.         private float m_StickToGroundForce;
    27.         [SerializeField]
    28.         private float m_GravityMultiplier;
    29.         [SerializeField]
    30.         private UnityStandardAssets.Characters.FirstPerson.MouseLook m_MouseLook;
    31.         [SerializeField]
    32.         private bool m_UseFovKick;
    33.         [SerializeField]
    34.         private FOVKick m_FovKick = new FOVKick();
    35.         [SerializeField]
    36.         private bool m_UseHeadBob;
    37.         [SerializeField]
    38.         private CurveControlledBob m_HeadBob = new CurveControlledBob();
    39.         [SerializeField]
    40.         private LerpControlledBob m_JumpBob = new LerpControlledBob();
    41.         [SerializeField]
    42.         private float m_StepInterval;
    43.         [SerializeField]
    44.         private AudioClip[] m_FootstepSounds;    // an array of footstep sounds that will be randomly selected from.
    45.         [SerializeField]
    46.         private AudioClip m_JumpSound;           // the sound played when character leaves the ground.
    47.         [SerializeField]
    48.         private AudioClip m_LandSound;           // the sound played when character touches back on ground.
    49.  
    50.         [SerializeField]
    51.         private Camera m_Camera;
    52.         private bool m_Jump;
    53.         private float m_YRotation;
    54.         private Vector2 m_Input;
    55.         private Vector3 m_MoveDir = Vector3.zero;
    56.         private CharacterController m_CharacterController;
    57.         private CollisionFlags m_CollisionFlags;
    58.         private bool m_PreviouslyGrounded;
    59.         private Vector3 m_OriginalCameraPosition;
    60.         private float m_StepCycle;
    61.         private float m_NextStep;
    62.         private bool m_Jumping;
    63.         private AudioSource m_AudioSource;
    64.  
    65.         // ...
    66.      
    67.         private void GetInput(out float speed) {
    68.             // Move on click down
    69.             float mouse = 0;
    70.             if (Input.GetButton("Fire1")) {
    71.                 mouse = 0.1F;
    72.             }
    73.  
    74.             bool waswalking = m_IsWalking;
    75.  
    76. #if !MOBILE_INPUT
    77.             // On standalone builds, walk/run speed is modified by a key press.
    78.             // keep track of whether or not the character is walking or running
    79.             m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
    80. #endif
    81.             // set the desired speed to be walking or running
    82.             speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
    83.             // m_Input = new Vector2(horizontal, vertical);
    84.  
    85.             // Get movement direction
    86.             m_Input = new Vector2(0, mouse);
    87.  
    88.             /*
    89.              * This does not work for some reason: OVRInput is not recognized in FPC ???
    90.              * But this is required for GearVR Controller interaction. It works like a charm in VRInput.
    91.              */
    92.             if (OVRInput.Get(OVRInput.Button.PrimaryTouchpad)) {
    93.                 // button is pressed, handle the touch.
    94.                 Vector2 touchPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
    95.                 m_Input = touchPosition;
    96.  
    97.                 const float scalingFactor = 0.1f;
    98.                 m_Input *= scalingFactor;
    99.             } else {
    100.                 m_Input = new Vector2(0, mouse);
    101.             }
    102.  
    103.             // normalize input if it exceeds 1 in combined length:
    104.             if (m_Input.sqrMagnitude > 1) {
    105.                 m_Input.Normalize();
    106.             }
    107.  
    108.             // handle speed change to give an fov kick
    109.             // only if the player is going to a run, is running and the fovkick is to be used
    110.             if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) {
    111.                 StopAllCoroutines();
    112.                 StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
    113.             }
    114.         }
    115.  
    116.  
    117.         private void RotateView() {
    118.             if (VRDevice.isPresent)
    119.                 return;
    120.  
    121.             m_MouseLook.LookRotation(transform, m_Camera.transform);
    122.         }
    123.  
    124.     }
    125.  
    126. }
    127.  

    Whereas I can use it without problems in other scripts. OVRInput is not in any namespace so I shouldn't have to define a using statement and Visual Studio can't help with the problem (it suggests creating a new type). Without the lines 92-101 the script works like a charm.

    I've run out of ideas what this could be.

    I am running Unity 5.6.0f3 on Windows 10 64-bit.

    Thanks for your help !
     
  2. omacha

    omacha

    Joined:
    Aug 21, 2017
    Posts:
    9
    Figured it out. The reason being that FirstPersonController being part of the Unity Standard Assets is being compiled in a "first wave", separately from the other scripts. The script OVRInput is not a part of this and therefore is not visible from the script in the standard assets.

    Credit goes to this answer. He refers to the following Unity doc:
    https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html
     
    billywafuu, NeatWolf and Dance_M like this.
  3. PhiKirax

    PhiKirax

    Joined:
    Feb 8, 2016
    Posts:
    10
    it would be nice to know how to solve the problem...
     
    mbentley3123 likes this.
  4. omacha

    omacha

    Joined:
    Aug 21, 2017
    Posts:
    9
    I solved it by writing my own controller in the project folder, but not using it from the Standard Assets folder. Essentially it's the same as copying it and changing the namespace.
     
    happymoep likes this.