Forum rules - please read before posting.

Problems with multiple menus & positioning for Unity UI in scene and Unity UI prefabs (Worldspace)

I have a lot of menus I'm working with, with which I've sorted out my gameplay, I'm now converting the menus to Unity UI WorldSpace to accomodate a VR experience (one prefab only, essentially I need to pipe the content of all the menus to that one prefab [or in scene UI] one after the other as they are clicked. And I have a line of code that matches the transform of the menu to a point in front of the player (let's call this 'menu position'). This works fine when using Unity UI in Scene, but for Unity UI in prefab, the original position of the prefab persists, even if I activate a different menu after 'menu position' has changed. Unity Ui in Scene on the other hand would not allow two menu's to be hooked up to the same canvas elements in scene. This has been driving me crazy for the past three days, each option has some of what I need but neither of them is letting me have it all!

P.S. I do not seem to have this problem if I use the 'follow cursor' positioning option for the menus, and that would have been most preferable, but because I'm building for VR, and I'm not using controllers - I'm relying on the ClickByHoveringCursor script that allows a 3d mesh stand in for a 3d cursor and trigger interactions if held over interractable objects for a certain length of time - it would be impossible to select elements on a menu with the same 3d cursor that the menu is following. If there was a way to work around this without meddling with controllers, I'd be very happy to consider it. 

Thanks in advance for any tips! 


  • Can you share screenshots to illustrate the problem?  As it's a visual issue, I think it's necessary to understand what's going on exactly.

    If the issue is that you need to reset/initialise your Menu(s) after a scene change, you can hook into the OnAfterChangeScene custom event:

  • Sorry I didn't get back on this.
    It was a simple thing eventually, but easily confusing, if you don't know what to look for. I had created a script called 'menu controller' to attach to each canvas prefab, and I was getting a reference to the canvas prefab through a public variable, I don't remember how the code ran but there was apparently something about it that made the Menu initialize at the original location for the prefab and stay there, rather than following the player / fps camera as intended. I saw some explanation in the unity forum that explained the issue and what to do, but sadly I can't remember what, I however drilled down to two lines of code in the update function of my menu controller script which works as intended. Here it is: 

    hudCanvas = this.gameObject;
    hudCanvas.transform.position = Camera.main.transform.position + Camera.main.transform.forward + offset; 

    The variable 'offset' is a vector 3 which I can adjust in the inspector to position the menu at whatever offset I want from the front of the camera. With this, the different menus appear in front of the camera during game play, all instantiated from the menu UI prefabs to which the menu controller script is attached. 
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.