- Home /
VRTK UI doesn't work after load scene
Hi guys,
I'm having a problem where every time I load to new scene, vrtk's ui stop working. Ui pointer just goes straight through canvas and can't interact at all.
Appreciate if someone shed a light on this for me.
Thank you.
finally got it, in the slack channel of VRT$$anonymous$$ they told me this: "Try doing VRT$$anonymous$$_SD$$anonymous$$$$anonymous$$anager.instance.enabled=false; before you switch scenes." -bddckr VRT$$anonymous$$
Answer by PandaFoxProductions · May 29, 2018 at 07:05 PM
I was having the same problem. I was able to resolve it by adding the EventSystem GameObject, that gets auto generated when you add a canvas, to the scene.,I was Having the same Issue, I was able to resolve it by adding an EventSystem object, that gets auto generated when you add a Canvas, into the scene.
Yeah, this is the correct answer - the reason it behaves so weirdly is that SD$$anonymous$$SetupSwitcher also has a fallback copy of EventSystem that it activates if it detects you don't have your own in the scene and that breaks for some reason when changing scenes (you should have your own EventSystem if you are using UI anyway). That fallback EventSystem also prevents Unity from auto-generating it when you add a canvas.
Answer by boulay_b · May 29, 2018 at 09:22 PM
I had the same problem and after a quick chat on the VRTK Slack I was told that it is related to the Unity EventSystem being disabled and not working properly. I managed to get it work with this script.
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using VRTK;
public class MenuFix : MonoBehaviour
{
public GameObject EventSystem;
public VRTK_UIPointer PointerController;
private VRTK_VRInputModule[] inputModule;
private void Start()
{
StartCoroutine(LateStart(1));
}
private void Update()
{
if (inputModule != null)
{
if (inputModule.Length > 0)
{
inputModule[0].enabled = true;
if (inputModule[0].pointers.Count == 0)
inputModule[0].pointers.Add(PointerController);
}
else
inputModule = EventSystem.GetComponents<VRTK_VRInputModule>();
}
}
IEnumerator LateStart(float waitTime)
{
yield return new WaitForSeconds(waitTime);
EventSystem.SetActive(true);
EventSystem.GetComponent<EventSystem>().enabled = false;
inputModule = EventSystem.GetComponents<VRTK_VRInputModule>();
}
}
As you can see, you also have to repopulate the VRTK_VR Input Module component yourself. The PointerController GameObject is my controller with the VRTK_UIPointer component attached to it. The input module is in an array because I have got some issues where sometimes VRTK generate multiple ones in the EventSystem when I enable it. Hope it helps!
Answer by codypiercey · Dec 05, 2017 at 09:06 PM
I am also having this issue. I will let you know if I find a solution. When running the scene by itself the UI works fine, however if the scene is loaded it no longer works.
Answer by sevag · Jan 17, 2018 at 12:58 AM
Also still having this exact issue, UI Pointer works fine on first scene, but stops working after any scene load using SceneManager.LoadScene, even if it's the exact same scene.
I've been using the latest version of VRTK 3.2.1 for this project.
I've tried adding 'VRTK_SDKManager.instance.enabled=false;' into script before switching scenes, same results.
I've tried adding 'VRTK_SDKManager.instance.enabled=false; VRTK_SDKManager.instance.enabled=true;' into script when new scene loads, same results
I've tried disabling/enabling the canvas itself on scene start.
I've tried updating Unity to 2017.3.0, same results.
It seems to be some kind of issue with the UI Pointer raycast. I have a script that toggles the straight pointer visibility on/off based on the pointers raycast hitting a canvas object, which no longer works after a scene load.
This is a crucial aspect of the game I'm building, any help would be greatly appreciated. I'll be sure to post any results that I come across.
Answer by oumur · Oct 04, 2018 at 03:00 PM
If you disable and enable the VRTK_UI Canvas script (after enabling the UI and the Event handler) it starts working again.