- Home /
Unity UI not working using VR Samples plugin after upgrading Unity to 5.4 or 5.5
Hello there. I have a working version of my app in unity 5.3.6 using vr samples prlugin. In my scene i have 3d game object what behave like button using vrinput.cs. I also have Unity build in buttons which works as well.
THE PROBLEM IS after I upgrade unity to higher version. I have tried 5.4 and 5.5 as well. Build in UI Buttons stop working. They dont change color on hover and doesnt respond to my clicks at all.
Is this the normal behaviour or there is a bug? I was not able to read about this anywhere in guideliness. I red in release notes for unity 5.4 about some changes but VR Samples plugin documentation says it si upgraded to the latest version of unity.
Thx for your time
Unfortunately, I cannot give you an answer to this (yet) ... I just found this while looking for an issue that seems to be similar or maybe even the same - except I saw this when going from Unity 5.4.3 to Unity 5.5:
In Unity 5.4.3, by applying a bit of magic, I could make sure that my in-VR laserpointer based UI always worked (the tricky part was getting both the companion Window UI and the in-game UI to work; and in fact, I can only use either one of them, not both at the same time).
In Unity 5.5, however, in-VR laser-pointer UI (using Unity's UI event system) only works when the game has focus.
I have also tried this with various 3rd party solutions (e.g. Vive Input Utility by ViveSoftware, http://u3d.as/uF7), and there I see the same problem: As soon as the VR window loses focus, the laser pointers stop working.
I'm still investigating this and trying to figure out a solution ... if I find one, I'll report back ;-)
Answer by jashan · Apr 01, 2017 at 12:38 PM
In Unity 5.5, UT did something very strange: They completely disable their event input system when an application loses focus (on desktop). This means that any hover effects will only work when the game really has focus - and in VR, if your game loses focus for some reason (e.g. because you do something via the SteamVR dashboard), there's really no way to get focus back.
Hopefully, this will be fixed in a later version of Unity - in 5.5, it's not fixed, and I believe in 5.6 it's also not fixed. The way to work around this is to write your own VREventSystem which overrides the stupid stuff that OnApplicationFocus(...) does in Unity 5.5 (activate a "paused" mode).
When using your own VRInput, you may also want to make sure it always is processed, regardless of any other input modules (e.g. StandaloneInputModule).
Here's what I use - please be aware that you cannot simply copy and paste this code and expect it to work because this uses my own MotionControllerInputModule that you probably don't have in your project, but it's easy enough to adapt this to work with your own custom input module:
using UnityEngine.EventSystems;
namespace NarayanaGames.VR.UI.UnityUI {
public class VREventSystem : EventSystem {
// IMPORTANT: "MotionControllerInputModule" is the custom VR input module
// I am using. You'll usually want to replace this with
// whatever laser-pointer / VR-UI input module you are using.
private MotionControllerInputModule motionControllerInputModule;
protected override void OnEnable() {
base.OnEnable();
motionControllerInputModule = GetComponent<MotionControllerInputModule>();
}
protected override void OnDisable() {
if (motionControllerInputModule != null) {
motionControllerInputModule.DeactivateModule();
motionControllerInputModule = null;
}
base.OnDisable();
}
protected override void OnApplicationFocus(bool hasFocus) {
/*
* Don't do anything, it's quite stupid to pause
* just because we lost focus. Think of VR :-/
*/
}
protected override void Update() {
if (current != this) {
return;
}
base.Update();
// NOTE: We always want to have VR-input being processed
if (motionControllerInputModule != null) {
motionControllerInputModule.Process();
}
}
}
}
Your answer
Follow this Question
Related Questions
Raycast a World Space UI with VR (Daydream) 1 Answer
How to make a 3D interactive map 0 Answers
Why isn't curved UI asset working? 0 Answers
How to display 3D object on top of UI World Space Canvas in VR 0 Answers
Dropdown not working with Oculus 3 Answers