Forum Discussion

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

Detecting Rift when using Playmaker?

Hi!

I'm trying to build an FSM in Playmaker to get my game to detect if the Rift is plugged in when I start it up, and then automatically switch from the OVRPlayerController to a standard camera/controller setup if the player does not have a Rift connected. I think "OVRDevice.IsHMDPresent()" is what I'm looking for but I'm such a newb that I don't know how to get that into Playmaker.

Thanks for any help!

8 Replies

Replies have been turned off for this discussion
  • Anonymous's avatar
    Anonymous
    Here is what I've got, in case anyone needs it or can improve upon it.

    1. I created an empty game object and called it VR Detector.
    2. I added the OVRDevice script from the SDK to it, along with a .cs script called Rift Detector, which I made based on the help in the threads above. Here is the content of that:

    using UnityEngine;
    using System.Collections;

    public class RiftDetector : MonoBehaviour {

    public bool RiftAttached = false;
    public PlayMakerFSM theFsm;

    // Use this for initialization
    void Start () {
    if (OVRDevice.SensorCount == 0)
    {
    RiftAttached = false;
    }

    if (OVRDevice.SensorCount > 0)
    {
    RiftAttached = true;
    }
    theFsm.FsmVariables.GetFsmBool("RiftPresent").Value = RiftAttached;
    }

    // Update is called once per frame
    void Update () {

    }
    }

    3. Created a Playmaker FSM that does a Bool Test against the variable RiftPresent. If Yes, it creates an OVRPlayerController game object and finishes. If No, it creates a standard First Person Controller and finishes.

    This is really just intended as a starting point. The idea is to have an easier way to simultaneously develop and test in VR and for standard displays. I should be able to go forward now in Playmaker without having to muck about with too much more code. :lol:
  • Great!
    Thanks for figuring that out (and actually getting back to us, often people just leave the question open)
  • Anonymous's avatar
    Anonymous
    This is the part that gave me the most trouble:

         theFsm.FsmVariables.GetFsmBool("RiftPresent").Value = RiftAttached;


    I kept trying to figure out which Playmaker Get action would make the FSM pull the value from the script. It turns out instead that the script sends the value to the FSM. At least I think that's what happens. :?
  • Anonymous's avatar
    Anonymous
    I forgot to mention one step. The Rift Detector script will have an empty field in the Inspector called "The Fsm" where you have to select the FSM in order for it to connect together. I'd expect there is a way to eliminate this step by declaring it directly in the script, but I couldn't get it to work.