Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
vardulov's avatar
vardulov
Honored Guest
11 years ago

Adding a OVRPlayerController in Unity 4 at Runtime

I'm using Unity 4.6 with Oculus 0.5 integration on a Mac OSX machine, and I attempted to add an empty game object, then attach a OVR Manager, OVRCameraRig, and OVRPlayerController to it. However attempting to run this stalls out my computer and crashed Unity.

Is this possible, or should I keep a disabled CameraRig that I simply enable when I need it after my terrain is enabled?

Also are there any good resources or documentation for using the OVR integration in the C# scripts for Unity? I have been searching but haven't found anything sold.

Thanks in advance for any help,
-Victor

6 Replies

Replies have been turned off for this discussion
  • What version of Unity specifically are you using? You should probably update to the latest patch of 4.6.x.

    You should also be using the OVRPlayerController prefab, NOT dragging the scripts onto an empty game object.

    Try to play the Room scene that comes with the Oculus integration to check that it works.
  • First off thank you for the response.
    To answer your questions:
    "cybereality" wrote:
    What version of Unity specifically are you using? You should probably update to the latest patch of 4.6.x.

    I downloaded the 4.6.6 about a week ago, I can try installing the 4.6.6p4 although I'm not sure if that's the problem.
    "cybereality" wrote:
    You should also be using the OVRPlayerController prefab, NOT dragging the scripts onto an empty game object.

    How would I use a script to create an instance of the OVRPlayerController prefab ?
    I thought that it was like prebuilt object that I could create like:
     OVRPlayerController nPC = new OVRPlayerController();

    but I received an error that the prefab can only be added as a component to another GameObject, which is why I elected in attempting to create an empty GameObject where I would use the AddComponent<OVRPlayerController>() . however as stated previously this also did not work.
    "cybereality" wrote:
    Try to play the Room scene that comes with the Oculus integration to check that it works.

    Do you mean just play it to see if the Oculus works, or try to build the game in Unity?
    I've built a demo that was literally 4 walls, a floor and a point light, where I did everything by hand in the Unity Editor, and I used the OVRPlayerController, and it worked exactly as I expected it to.
    I was thinking: Is it even possible to add an instance of the Player Controller using a script? Perhaps the better thing to do would be to have a disabled OVRPlayerController that becomes enabled and positioned when the terrain is loaded?
    Thanks again for your help, I'm very new to all of this so I really appreciate all the advice I can get!
    -Victor
  • Here's how to do it.

    Create a new C# script (for example, on an empty game object in the scene) called "SpawnPrefab".

    using UnityEngine;
    using System.Collections;

    public class SpawnPrefab : MonoBehaviour {
    public GameObject thePrefab;

    void Start () {
    Instantiate(thePrefab, Vector3.zero, Quaternion.identity);
    }

    }


    Then drag the OVRPlayerController prefab from the folder "OVR/Prefabs" onto the "The Prefab" inpector property on this new script. You can also edit the script so it can take a specific position or orientation if the player needs to start somewhere special. Hope that helps.
  • can this instancing be used for Multiplayer ? im trying to but only one camera in the scene works.
    the other players camera dont work.