New To The Forum? Click Here To Read The How To Guide. -- Developers Click Here.

New Unity UI + OVR Look-Based Input HOWTO

13

Comments

  • leftbigtoeleftbigtoe Posts: 46
    Brain Burst
    First, thanks for the great script ccs, saved me a lot of headaches!

    Just a quick thing to watch out for when using the cursor:
    if you are using a cursor, add a CanvasGroup element to it and make it non interactable and not blocking the raycasts, otherwise your elements will only be selected briefly before the raycast to the actual element is blocked by the freshly placed cursor.
  • muralivmuraliv Posts: 23
    Brain Burst
    Hello
    I tried this script and it works fine. Iam using samsung gear VR with the touchpad in the device.
    I have a panel with a scrollrect and inside a horizontal grid layout with images dynamically placed in them.

    Now for the scroll rect, if i try to scroll, it works only when i touch on the touchpad and rotate my head to do the scroll.

    If i do a swipe on the touchpad, it does not scroll
    Can you please help me to fix this.

    Thanks
  • ccsccs Posts: 219
    Hiro Protagonist
    OculusDev wrote:
    I have an issue that I'm trying to solve with the UI button. If I look at the button and click on it then the button continues to be rendered in a "clicked" state even when I look away from it. I have to click on a non-UI element to deselect the button.

    Sorry for my slow response on some of these. Been busy with day job + summer vacation + VR development.

    Instead of BasicLookInputModule.cs, look at the other example I posted, LookInputModule.cs. It includes button up code to handle what you are describing:
    // have to handle button up even if looking away
    		if (Input.GetButtonUp(submitButtonName)) {
    			if (currentDragging) {
    				ExecuteEvents.Execute(currentDragging,lookData,ExecuteEvents.endDragHandler);
    				if (currentLook != null) {
    					ExecuteEvents.ExecuteHierarchy(currentLook,lookData,ExecuteEvents.dropHandler);
    				}
    				lookData.pointerDrag = null;
    				currentDragging = null;
    			}
    			if (currentPressed) {
    				ExecuteEvents.Execute(currentPressed,lookData,ExecuteEvents.pointerUpHandler);
    				lookData.rawPointerPress = null;
    				lookData.pointerPress = null;
    				currentPressed = null;
    			}
    		}
    
  • ccsccs Posts: 219
    Hiro Protagonist
    JagaHee wrote:
    Hello ccs
    Thank you for posting this code. Very useful. I have a question about BasicLookInputModule. As you wrote in instruction, i've attached the script to EventSystem object. And disabled touch input module and standalone. Then i need to deactivate lookInput and activate touch and standalone. But when i do this strage thing happens. Touch works only when by a second finger and Input system says it is the first finger. Do i need to clean something or stop any Input system somewhere?
    p.s. sorry for my english)

    I don't use touch input or standalone module at all, but my guess is the EventSystem calls Process function on ALL input modules, even if they are deactivated, and the BasicLookInputModule is grabbing some of the events so they don't appear to the TouchInputModule. In the BasicLookInputModule.cs code Process function, you could test this theory by adding an "if enabled" around all the code that is in that function now:
        public override void Process() {
             if (enabled) {
                 ...put all original contents of this function inside here...
             }
        }
    

    Another thing to test would be to remove BasicLookInputModule.cs (instead of deactivate) to see if the problem goes away. If that doesn't fix it, it points to some other issue not related to BasicLookInputModule at all.

    ccs
  • ccsccs Posts: 219
    Hiro Protagonist
    leftbigtoe wrote:
    First, thanks for the great script ccs, saved me a lot of headaches!

    Just a quick thing to watch out for when using the cursor:
    if you are using a cursor, add a CanvasGroup element to it and make it non interactable and not blocking the raycasts, otherwise your elements will only be selected briefly before the raycast to the actual element is blocked by the freshly placed cursor.

    There is a simpler way. The cursor should already be on its own Canvas as in the example I posted, and every Canvas has a Graphic Raycaster component that goes with it. Simply disable the Graphic Raycaster and the cursor won't block anything.

  • ccsccs Posts: 219
    Hiro Protagonist
    muraliv wrote:
    Hello
    I tried this script and it works fine. Iam using samsung gear VR with the touchpad in the device.
    I have a panel with a scrollrect and inside a horizontal grid layout with images dynamically placed in them.

    Now for the scroll rect, if i try to scroll, it works only when i touch on the touchpad and rotate my head to do the scroll.

    If i do a swipe on the touchpad, it does not scroll
    Can you please help me to fix this.

    Thanks

    It would probably be a bit of work to get the touchpad working. GearVR touchpad is handled throuh the Input.*mouse* interface. You would need to capture mouse point each frame, and then look at the change in y or x (depending on how you want to scroll). Here is some quick untested code to try to point you in right direction (should go in the Process() function):
    Vector2 mousePoint = Input.mousePosition;
    Vector2 changeMouse = mousePoint - lastMoustPoint;
    float someFactor = 0.002f;
    
    if (Input.GetMouseButtonDown(0)) {
        // touch pad is being pressed
        // send scroll event to current selected 
        Scrollbar sb = eventSystem.currentSelectedGameObject.GetComponent<Scrollbar>();
        if (sb != null) {
           sb.value += changeMouse.y * someFactor;
        }  
    }
    
  • uhcacinorevuhcacinorev Posts: 2
    NerveGear
    Hi,

    I've been reading through these posts and know that these fixes are mostly for Unity 4, but I'm working in Unity 5. I was wondering if anyone has been able to get the GUI to work in Unity 5 so far, since I'm having issue with a simple GUI text not showing up when in play mode. It looks as it should in the game view; however, once its in play mode the GUI disappears. I've tried checking if its obscured by objects by deleting them in play mode, but it's just not there.
  • ReactorReactor Posts: 1
    NerveGear
    Hi,

    I've been reading through these posts and know that these fixes are mostly for Unity 4, but I'm working in Unity 5. I was wondering if anyone has been able to get the GUI to work in Unity 5 so far, since I'm having issue with a simple GUI text not showing up when in play mode. It looks as it should in the game view; however, once its in play mode the GUI disappears. I've tried checking if its obscured by objects by deleting them in play mode, but it's just not there.

    Hi uhcacinorev,

    Are you sure you have your canvas set to "World Space"?
  • ccsccs Posts: 219
    Hiro Protagonist
    The demo package I posted on 1st page works fine in Unity 5. Unity 5 is all I am using these days.
  • ccsccs Posts: 219
    Hiro Protagonist
    Just to be sure, I confirmed the zip file I posted in the 1st post works with Unity 5.1.2p2 (and probably other Unity 5 versions) and OVR runtime 0.6.0.1. It does require 1 small fix to OVRMainMenu.cs to be compliant to new API:

    Change line 283 to this:
    #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2

    Then it should work as posted. Keep in mind this is using old legacy-integration and not new built-in VR mode that is now available in Unity. I'll see if I can find time to create and post an updated version that uses new native integration.

    I haven't tried running 0.7.0.0 runtime yet either. I'm in the process of moving to that now for my other projects, and I'll try this one out just to make sure it still works.
  • Hi, great work!
    Did you had a time to check the new Unity 5.2 version with your code and example . As it support 0.7 runtime now.
    Thanks for the share :)
  • GroundControlGamesGroundControlGames Posts: 36
    Brain Burst
    Hey there,

    This work is awesome, but it won't run properly on Unity 5.2.2 . I get all sorts of weird behaviours (flickering, no image, etc.) and the interactions won't work.

    Anyone else managed to get it working under Unity 5.2.2?
  • ccsccs Posts: 219
    Hiro Protagonist
    Here is an updated version of the project that works with 5.2.1p2 (5.2.2 should work as well) and uses Native VR + 0.1.2 Oculus Utils so it is compatible with latest Oculus runtimes (0.7 or 0.8):

    https://www.dropbox.com/s/g8ptl7w9xdewp ... 5.zip?dl=0

    I'll update the 1st post as well. I'll leave the old version linked there in case anyone wants to still use the old Oculus integration.

    ccs
  • motorsepmotorsep Posts: 1,094
    Nexus 6
    Does it use uGUI and does it work on Gear VR ?
  • ccsccs Posts: 219
    Hiro Protagonist
    Yes it uses uGUI and yes it works with GearVR with a bluetooth controller and limited function with the touchpad. If you want to get fancier with the GearVR touchpad to add scrolling of scrollbars or use it to control the cursor beyond just center look position, that is something you would have to add. Currently scrolling is mapped to right stick y-axis and trigger axis (on an xbox 360 controller on desktop). The touchpad, however, will work as equivalent button press/release and allow you to control everything in this scene with look based scroll or submit.

    ccs
  • GroundControlGamesGroundControlGames Posts: 36
    Brain Burst
    ccs wrote:
    Here is an updated version of the project that works with 5.2.1p2 (5.2.2 should work as well) and uses Native VR + 0.1.2 Oculus Utils so it is compatible with latest Oculus runtimes (0.7 or 0.8):

    https://www.dropbox.com/s/g8ptl7w9xdewp ... 5.zip?dl=0

    I'll update the 1st post as well. I'll leave the old version linked there in case anyone wants to still use the old Oculus integration.

    ccs

    It's working like a charm now on Unity 2.2.2. Great work my friend ;)
  • vrguy2vrguy2 Posts: 40
    Hi guys, so I'm trying to make a Gear VR app that showcases some various models with different animations on each model, using various button they press on the wall in VR. I have about 10 of these models, all with animator controllers attached. I'm using the button script from this post (with the gaze based looking/selection).

    The issue is I have no idea how to make so after I click the button it spawns one of the models I specify from my assets folder, plays the animation in the model (fbx models with animator controller that is attached to the model too) and plays the sound for that animation. I tried messing with the on click () stuff that was included, it was directed to a testevents script but I didn't know what to do with that.

    I feel like what I'm trying to do is a very simple concept but I have been spending over a week now! Any help would be greatly appreciated. I really want to make this Gear VR app happen. Do I need a special script to replace the testevents script to make this happen?
  • petereptpeterept Posts: 167
    Art3mis
    What you can do is, create a prefab for your animation, then instantiate the prefab when they click the button.

    Firstly, create a game object at 0,0,0 and add your animation as a child. Add your audio source and set it to play automatically (so if you hit PLAY in editor you hear the sound immeadiately). Add your animation and set it to play automatically (in your FBX import animations).

    OK, if you hit play and everything looks good you are 3/4 of the way there.

    Now, drag that game object into the project to save it as a prefab.

    Now, create a script to add to each button that has a variable for a prefab and a location to spawn it. Give it a script to handle the click. Then drag your prefab onto the variable, and your spawn location, and also tell your button's click event to call that method.

    Here's some rough pseudo code:
    class SpawnAnimation : MonoBehaviour
    {
      public GameObject prefab;
      public Transform spawnTransform;
    
      public void Spawn()
      {
        GameObject go = (GameObject)Instantiate(prefab, spawnTransform.position, Quaternion.identity);
        go.SetParent(spawnTransform);
      }
    }
    
    Check out my Unity VR development blog:
    http://talesfromtherift.com
    @peterept
  • vrguy2vrguy2 Posts: 40
    Thank you peterept. this gives me some hope to finally figure this out. I'll be back tomorrow (posting from my phone) and let you know if it worked!
  • vrguy2vrguy2 Posts: 40
    Hey peterrept, so I tried it today but having issues still. Just to give you an example of how I have the models laid out, one is named "guy.fbx" inside the fbx I can expand it and there is an animation in there called "walk.vmd" (I use MMD4mechanim to make these) There is also a walk animation in the audio folder called "walk.wav" that syncs with the animation.

    I right clicked the walk.vmd and created a prefab called "guywalk" then I replaced the testevent with this:
    using UnityEngine;
    using System.Collections;
    
    class SpawnAnimation : MonoBehaviour
    {
        public GameObject guywalk;
        public Transform spawnTransform;
    
        public void Spawn()
        {
            GameObject go = (GameObject)Instantiate(guywalk, spawnTransform.position, Quaternion.identity);
            go.SetParent(guywalk);
        }
    }
    

    I seem to be getting an error when I try to launch. I am so bad with C# I'm sorry, I'm a lot better with the art stuff really. I made 3 separate grey buttons on the wall that link to the testevents script copies, but when I tried to make the buttons go to a copy the on click () changes to "no function" so that's a separate issues I'm having also. Any help with my "total noobness" would be greatly appreciated.
  • petereptpeterept Posts: 167
    Art3mis
    Hey, I'm not at my dev computer right now, but I'll help you later on.

    But for now here some steps: there is 2 pieces to the puzzle:

    1. Spawning your guy (and probably destroying also)

    2. Make your guy prefab

    You can test step 1 above with a simple prefab:

    - Create an empty game object (name it "guy" and then create a simple 3d cube as it's child.
    - Drag the guy game object into your project hierarchy and it will now be a prefab.
    - Delete the guy from your scene.
    - Assuming you have your UI button in the scene with the spawn script attached:
    - Drag the guy prefab onto guywalk property
    - Create an empty game object in the scene for your spawn spot, then drag it onto the script at spawnTransform prop.

    Now run the scene, when you press the button your cube should appear. If you press again, you'll actually get another cube over the old one. You could use this code to remove any children before you spawn a new one:

    foreach (Transform child in spawnTransform) {
    GameObject.Destroy(child.gameObject);
    }

    So if that all works, now it's a matter of working on your prefab guy to slowly add in the animated character, sounds, etc.

    HTH
    Check out my Unity VR development blog:
    http://talesfromtherift.com
    @peterept
  • SvenVikingSvenViking Posts: 296
    Hiro Protagonist
    I don't know if this matters or helps anyone, but a related tutorial and example project was recently posted on the Oculus Blog.
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux)
    Jungle Juice
    Sven Co-op
  • vrguy2vrguy2 Posts: 40
    Thank you peterept and sven, I did just try that second project sven linked to but it seemed really complicated. I could not get an OVRplayercontroller to work with it at all, even after following the blog step by step, I couldn't figure out how to link the model to the buttons they had either. It seems I'm not able to get this going still.

    I am definitely doing something silly I know it. I have re-read your instructions about 20 times try to do it step by step. Is there any simple modifications I could make to the script you gave me earlier that would accomplish the same thing, where I could just drag one script for guy.fbx to the button and one for girl.fbx to the other button.. doing all the sound, destruction, spawning? Or maybe there is a Unity asset store project I could purchase that I could just drag and drop my model to replace what they have, if they have UI buttons ready to go? I have a guy.fbx that's ready to go and girl.fbx, with the VMD animations inside the fbx and the sounds in the assets folder.

    I would gladly paypal someone to help me figure this out at this point. I am basically trying to make something similar to that old "Miku Entertainment Sphere" demo, but for Gear VR utilizing my models and sounds. I feel like this is Unity 101 and I can't even do something as simple as make a model spawn with an animation and sound playing when press various buttons on a UI button in VR. Using the Oculus Audio SDK will complicate this even further I am guessing.

    Edit: I just realized it might be easier to describe what I am trying to accomplish as a VR character selection screen. To be more specific I am getting stuck here on your instructions:
    - Assuming you have your UI button in the scene with the spawn script attached:
    - Drag the guy prefab onto guywalk property
  • dignifiedwebdignifiedweb Posts: 273
    Art3mis
    Hi ccs,

    I really appreciate the work you've done here. I am experiencing a weird problem, hoping you had an idea what's going on. I used your code in Unity 4.5x and it worked great, but now with the new runtime, I wanted to use Unity 5, naturally upgrading. I upgraded no problem with the new Unity Oculus Integration, everything was pretty easy and straightforward. So, as a metric, I ran your sample and it works great, so the issue is definitely not with your code.

    With my old project I made a "look camera" as you described. In my new project, the cursor moves using this look camera, but it now has a really strange drifting problem, where it'll drift away from the center, so it ends up being away from where you're looking. Again, your sample doesn't have this issue, I even imported the latest 0.1.3.0 OculusUtilities package to make sure.

    Comparing your sample and my old project, you don't seem to have a "look camera" anymore, but rather use the "CenterEyeAncher" for the "Event Camrea" on the cursor GameObject. Also, you seem to add the oculus supplied prefab "OVRTrackerBounds" as a child object. I am creating a simple OVRCameraRig setup, so I butchered your sample and dragged the "OVRCameraRig" out and it still works, I can't seem to break your code in the same way. I've copied over your latest code to my project, no luck so far. If I use the "CenterEyeAncher" the same as you, my cursor doesn't move, it just sits there. Any hints or idea what I could be doing wrong? It seems like I'm missing something simple. After sleeping on it, I may figure it out tomorrow night, but any ideas would be much appreciated. Thanks.
    Check out my Mobile VR Jam 2015 title Man Overboard! - Try the DK2 Version if you don't have a Gear VR
  • ccsccs Posts: 219
    Hiro Protagonist
    The only thing I can think of is the cursor object you are pointing to is not at 0,0,0 position on the canvas the cursor is a part of. The code moves the cursor canvas transform where the look raycast hit occurs. Then the code scales the cursor based on distance. If for some reason the cursor sprite was not perfectly centered, the scaling could make the cursor appear to float away from center based on distance. You could test this theory by turning off "Scale Cursor With Distance" option on LookInputModule to see if that changes anything.

    One other possibility. Perhaps you don't have the Graphic Raycaster component disabled on the cursor itself. If you don't, what could happen is the screen raycast into the scene could actually be hitting the cursor, and then adjusting the cursor position based on the raycast hit. I would think this would cause the cursor to readjust position and move and keep doing that in a loop.

    Good luck.

    ccs
  • dignifiedwebdignifiedweb Posts: 273
    Art3mis
    ccs wrote:
    The only thing I can think of is ...

    Those were good suggestions, but none of them worked unfortunately. If I figure it out, I'll let you know, but for now I am going to try the Oculus one to see if it works by swapping it in. Thanks again!
    Check out my Mobile VR Jam 2015 title Man Overboard! - Try the DK2 Version if you don't have a Gear VR
  • hi! im trying to load different scenes for each button of your tutorial, and when i add the script for every button, only works at the first one. Any idea?
    thanks!!

    load scene code
    using UnityEngine;
    using System.Collections;
    
    public class ButtonNextLevel : MonoBehaviour 
    {
    	public void NextLevelButton(int index)
    	{
    		Application.LoadLevel(index);
    	}
    
    	public void NextLevelButton(string level2)
    	{
    		Application.LoadLevel("level2");
    	}
    }
    
  • ccsccs Posts: 219
    Hiro Protagonist
    Assuming you are passing the level's string to NextLevelButton from the Button On Click () event (in the inspector), it looks like you have a bug in the code. You are passing the string "level2" to Application.LoadLevel instead of the variable level2:
    Application.LoadLevel("level2");
    

    Should be:
    Application.LoadLevel(level2);
    

    Then in inspector assign the level name to the On Click action call string entry.
  • muralivmuraliv Posts: 23
    Brain Burst
    Hello,
    How do I make a scroll of the scroll rect component when i swipe on the GearVR touchpad. This is not working currently.
    Please let me know. Thanks
  • muralivmuraliv Posts: 23
    Brain Burst
    Hi
    I couldnt make this code to work

    Vector2 mousePoint = Input.mousePosition;
    Vector2 changeMouse = mousePoint - lastMousePoint;
    float someFactor = 0.002f;

    if (Input.GetMouseButtonDown(0)) {
    // touch pad is being pressed
    // send scroll event to current selected
    Scrollbar sb = eventSystem.currentSelectedGameObject.GetComponent<Scrollbar>();
    if (sb != null) {
    sb.value += changeMouse.y * someFactor;
    }
    }

    Whether it is the scrollbar component or on the scrollrect, I have to touch using the touchpad (mousedown) and then rotate my head to do the scroll.
    The swipe does not make the scrollrect to scroll
    Can anyone guide me on this pls
    Thanks
Sign In or Register to comment.