Forum rules - please read before posting.

World Space Canvas in VR not working

Hi! I'm developing a game based on Unity 5.6 + Google VR SDK 1.30 + AC 1.56b.

Because it's a VR project, I need to use world space render mode in all the Menu Canvas, also I'm using the "Unity UI In Scene" option for each menu.

The problem I have is when I'm trying to show any menu: in Unity editor works fine but when I deploy it to any Android device none of the menu shows up.

As an example, these are the steps to reproduce the issue:

1) Create a new project on Unity 5.6 using Google VR SDK 1.30 and AC 1.56b
2) Run the AC Game wizard.
3) Create a Player, with the VR Main Camera as a child.
4) Create a Canvas for the subtitles and properly configure it on the menu settings: using world space as render mode and "Unity UI in Scene" option.
5) Create a hotspot, with "play speech" as the use interaction.

So, when this example is running in the Unity Editor works fine, but when is running on any Android device, the subtitles never shows up.

Also, if I use the same canvas, and manually execute "SetActive (true)" and "SetActive (false)" works fine.

Are there any difference between Unity Editor and a real Android device that I should take in mind with AC?

Thanks!



Comments

  • Welcome to the community, @activia.

    Thank you for the clear steps.  At first glance, I wonder if this is due to your parenting of the MainCameraVR prefab to your Player.

    When on mobile devices, Unity has some very hard-to-spot differences when dealing with objects that survive scene changes, like the player.  Is your Player instantiated at runtime, or is he present in the scene file?

    Try unparenting the MainCameraVR - as a general rule, the MainCamera should be left alone whenever possible.

    If that fails, we may have to make one or two debug logs that we can use to see where the issue lies.  Menus are turned on in Menu.cs' TurnOn() function - but let's see if the parenting change has any effect first.
  • That was a good tip!

    I just attached the main camera to another GameObject and the menu started working on android devices.

    Thanks!

  • I'm still having the same problem, but it seems to be very randomly.

    Digging a little dipper with Andriod debugger, I found this:

    In Menu.cs, this line:






    localCanvas = Serializer.returnComponent <Canvas> (canvasID, KickStarter.sceneSettings.gameObject);


    Is called two times on Android devices for each Menu, but just one time when you run it on Unity Editor. 

    The problem is that the second time on Android "returnComponent" returns "null" so the canvas can't be activated.

    I fill like "GetOwnSceneComponents" inside "returnComponent" is not working in some situations, could it be because Unity 5.6?

    Thanks!






  • It could very well be - sorry I didn't pick that up earlier.  While Unity 5.6 is still in beta, AC can't officially support it - but it will need to be looked into.

    If you're aware that Android is calling this twice, does that mean you have a stacktrace to share?  I'll need to see where this second call is coming from.  I shall look into it on my own device, but the more information you can share, the more thorough I can be.

    Are you duplicating this Menu for each line in your Menu's properties box?
  • Hi Chris, here are the both stacktrace, just to be a little more clear: the function "LoadUnityUI" is called two times for each Menu, thats mean none of the Menu (I create 4 menus) are working:

    Stacktrace of the first call:
    AC.Menu.LoadUnityUI () in .../Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:301
    AC.PlayerMenus.RebuildMenus (menuManager=(null)) in .../Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:133
    AC.PlayerMenus.OnStart () in .../Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:89
    AC.StateHandler.InitPersistentEngine () in .../Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:81
    AC.StateHandler.OnAwake () in .../Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:71
    AC.KickStarter.SetPersistentEngine () in .../Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:130
    AC.KickStarter.OnAwake () in .../Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:964
    AC.MultiSceneChecker.Awake () in .../Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:46

    Second call:
    AC.Menu.LoadUnityUI () in .../Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:301
    AC.PlayerMenus.AfterLoad () in .../Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:248
    AC.SaveSystem.ResetSceneObjects () in .../Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:2156
    AC.SaveSystem._OnLevelWasLoaded () in .../Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:782
    AC.SaveSystem.SceneLoaded (_scene=, _loadSceneMode=) in .../Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:66
    UnityEngine.SceneManagement.SceneManager.Internal_SceneLoaded (Parameters=) in /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/SceneManagerBindings.gen.cs:245

    Thanks again for your help!

  • BTW, I change this line:






                else if (menuSource == MenuSource.UnityUiInScene)

                {                    
    localCanvas = Serializer.returnComponent <Canvas> (canvasID, KickStarter.sceneSettings.gameObject);
                }  

    by:






                else if (menuSource == MenuSource.UnityUiInScene)

                {

                    if (canvas == null) {

                        localCanvas = Serializer.returnComponent <Canvas> (canvasID, KickStarter.sceneSettings.gameObject);

                    } else {

                        localCanvas = canvas;

                    }

                }
      


    And is working fine right now, but I think is not a good solution.

  • You're right.  The larger issue is that all code that should be running after a scene change is doing so when the game begins.  That could create other problems elsewhere.

    This is indeed down to Unity 5.6.  I shall look into a workaround.
  • Revert back the change you made to Menu and open SaveSystem.  Replace the code starting line 53:

    #if UNITY_5_4_OR_NEWER
    private void Awake ()
    {
        UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneLoaded;
    }
    private void OnDestroy ()
    {
        UnityEngine.SceneManagement.SceneManager.sceneLoaded -= SceneLoaded;
    }
    private void SceneLoaded (UnityEngine.SceneManagement.Scene _scene, UnityEngine.SceneManagement.LoadSceneMode _loadSceneMode)
    {
        if (Time.time > 0f)
        {
            _OnLevelWasLoaded ();
        }
    }
    #else
    private void OnLevelWasLoaded ()
    {
        _OnLevelWasLoaded ();
    }
    #endif


    with the following:

    #if UNITY_5_4_OR_NEWER
    private bool loadedInitialScene = false;
    private void Awake ()
    {
        UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneLoaded;
    }
    private void OnDestroy ()
    {
        UnityEngine.SceneManagement.SceneManager.sceneLoaded -= SceneLoaded;
    }
    private void SceneLoaded (UnityEngine.SceneManagement.Scene _scene, UnityEngine.SceneManagement.LoadSceneMode _loadSceneMode)
    {
        if (loadedInitialScene)
        {
            _OnLevelWasLoaded ();
        }
        loadedInitialScene = true;
    }
    #else
    private void OnLevelWasLoaded ()
    {
        _OnLevelWasLoaded ();
    }
    #endif


    Does that solve the issue?
  • Nice, is working fine right now!
  • Good, thanks for testing.  I'll include an official fix in v1.56d.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.