Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

How to initialize a UGUI menu(inventory) manually.

edited December 2016 in Technical Q&A
Hi, I have a situation where I want to attach the inventory menu (worldspace) to the left controller in VR. During testing I setup the menu to be "Unity In-scene" and parented the menu to the [CameraRig], which worked perfectly in the test scene. But, now that I have transfered the contents to the main project, with real scenes, I have noticed some scenes initialize the inventory but others don't, even if the player is manually placed in the scene (I can tell the inventory is not initializing because when it loads properly AC hides the empty slots, but when it doesn't, I get the placeholder images I put in the slots, and of course, it doesn't work). 

Except for the size, I can't really see anything else different between the scenes,  and I know the controllers have a small delay in loading cause SteamVR needs to check if the physical controllers are connected. Still, I tried to unparent the inventory from the player and put it directly in one of the scenes (with the issue) and same thing, only placeholder images appear in the slots.

So, how would I go about initializing an inventory menu manually through scripting? I mean, connecting it to the UGUI and starting it up, to me it just's seems like the timing between AC loading and the UI loading is off. So it would probably be best if I cal the code manually when it' safe to do so.

Comments

  • edited December 2016
    Report: I unticked "Load Scenes Asynchronously" in the settings manager and the inventory in a few of the scenes which were having the issue, started to work again, but still, not in all of them. so I'm still interested in the correct way to initialize the inventory manually.

    Ah, to clarify, the inventory (worldspace) is parented to the Left controller, inside the [CameraRig] (the rig currently has the Player Script, so for now, the [CameraRig] is our Player).
  • To eliminate being misled by other systems contributing, I would advise you un-parent your UI from anything so that it's in a fixed position in world space while this problem exists.

    We should assume that the Menu itself (so far as AC is aware of it) is OK in all scenes.  To sync an AC's Menu to its Unity UI prefab manually, call LoadUnityUI.  So, e.g.:

    AC.PlayerMenus.GetMenuWithName ("MyMenu").LoadUnityUI ();

    There's more to it behind the scenes though, but AC handles all of this automatically within PlayerMenus' RebuildMenus function, which should probably be the first thing to try running manually:

    AC.KickStarter.playerMenus.RebuildMenus ();

    There must still be some key difference between the scenes that work vs those that don't, but it sounds like it could be due to a conflict with the other systems you have running.  Try placing Debug.Log commands in the LoadUnityUI function to see exactly what's going on.
  • I don't know about code conflicts... Really, the scene where I saw it not work the most before was pretty much clean, the difference is that there's tons of particle systems and audio (for dust storms) and a very big terrain and several 3D models. The other scene where it was happening was also a very large interior level, so all I can think of is a loading delay due to the size or the amount of art/effects in the scenes. 

    The same prefab for the camera rig is used in all levels, so it doesn't make any sense to think that that one is the cause (or the scripts within it), in fact turning off Asynchronous Loading actually fixed the issue in the big interior scene, so it's hard to say it has anything to do with what the systems are "doing", and more about "when" the general scripts are loading. I don't know if the SteamVR adds a delay (but it's 100% true that there's a delay in the rendering, cause everything is rendered twice in VR). But, anyway, I've added the RebuildMenus method to be run at the same time as the controllers turn on.  I'll be testing it today, so hopefully I'll report something soon.

    PS: Ah, about the interactions menu I mentioned in another post, that is only parented to an empty (as a folder), and was not working even in my test project scene, even when I was using VR emulation or not, just moving the hotspot detectors manually to show the menus. I wonder if maybe SteamVR takes some of the loading time... but anyway, I'll be checking this soon.
  • Ah, forgot to mention, calling RebuildMenus when the controllers turn on did the trick, thanks!
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.
Do NOT follow this link or you will be banned from the site!