Skip to main content
Up and Coming
December 8, 2013

Subclassing OVRPlayerController

For my game, I want to subclass OVRPlayerController to make my own player controller. I want to keep all the benefits that the OVRPlayerController provides while implementing my own custom functionality (like custom sprinting). Also, as long as the API doesn't change, I can update my Oculus Rift SDK without worrying about my code breaking. I do not get this benefit if I modify OVRPlayerController.cs myself.

Unfortunately OVRPlayerController uses private variables in many functions (like UpdateMovement). I am unable to maintain similar functionality in my subclass of OVRPlayerController because I cannot modify these variables. Ideally, any variables used in public functions would be made protected so that a subclass of OVRPlayerController can modify them.

Obviously I can change the script myself, and I probably will for the time being. My hope is that someone at Oculus will see this post and they can make a more extensible API for us.

If I am missing something here, please let me know. My goal is to solve this problem, not to complain.

If you are having the same issue or a similar one, please post and share!
    This topic has been closed for replies.

    7 replies

    Up and Coming
    December 8, 2013
    Here's what I'm thinking you could do.

    Make OVRPlayerController a partial class, that means you'll have to update it each time you download a new version but at least you will get a compiler error if you forget to do it and it's quick and easy to do.

    But partial won't be enough because no doubt you want to override stuff as well. So use your own partial class to elevate the private variables you need from private to protected, then make another class to inherit from OVRPlayerController and you can go about your overriding and customised actions.

    So in code...
    OVRPlayerController.cs
    public partial class OVRPlayerController { ... }


    OVRPlayerControllerExtended.cs
    public partial class OVRPlayerController { 
    // Elevate the access of the variables you need
    protected float Whatever {
    get { return _privateWhatever; }
    set { _privateWhatever = value; }
    }
    }


    MyOVRPlayerController.cs
    public class MyPlayerController : OVRPlayerController {
    // Do all your customisation here
    public new void update {
    var variable = Whatever; // private variable should be accessible
    base.Update(); // If you want...
    }
    }


    I can't test this at the moment to see if it works but it should be fine.
    Scott Vandonkelaar Zero Latency - Inversion VR
    Inspiring
    December 9, 2013
    Honestly the OVRPlayerController is more of an example than anything that should make it into a final game. You can use it as a basis for your code, but you will likely need to do a lot of custom stuff to integrate it well into your game.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    February 7, 2014
    Thanks for the info cyberreality. I'm new to Unity and the Rift so please bear with me and I'm new to the forum so I'm tacking on to this post as I'm also in a similar boat. I simply want my FPS character to swim. I could easily do this with a custom rigidbody / collider based character attached to the OVR camera controller but I worry about a lot of the custom Rift code in the player controller that could potentially degrade the experience. Modifying the OVR player controller has me really worried as it is a script with not much customizability and I do not want to have to deal with mods every time I upgrade. Is my best bet to define my own custom rigidbody / collider based FPS controller and then attach that to the OVR camera or should I stick with modifying the OVR character controller? Won't I be running into all sorts of Rift specific issues if I only rely on the camera controller?

    Thanks in advance!
    Inspiring
    February 8, 2014
    The easiest thing to do is to use the Unity FirstPersonController and replace the MainCamera with the OVRCameraController. There are just a few small modifications you need to get this to work. See this post: viewtopic.php?f=37&t=3018#p37280

    I have not tested this with swimming but it works with moving platforms and stuff like that so it may be all you need.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    February 8, 2014
    Thanks, I will go that direction. Is there any reason behind why you'd use the Unity FPController over the OVRPlayerController that comes in the Unity OVR integration package?
    Inspiring
    February 8, 2014
    I know specifically that the OVRPlayerController doesn't work well with moving platforms (ie elevators, etc.) while the Unity FPController does. I didn't look too deep to find out why. I bet you could fix the OVRPlayerController with a little work but haven't explored it myself.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    February 8, 2014
    Thanks. The solution you gave above worked for me.