Author Topic: Why isn't the UI Root the same size as the camera  (Read 5703 times)

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Why isn't the UI Root the same size as the camera
« on: December 06, 2016, 04:03:41 PM »
ive created new scene with a new 2D UI then adding a sprite to the screen added an anchor
my first question is why is the root UI different size to the actuall screen size
seconds question why does the anchor attach itsself to the root UI rather than the actual screen size

the reason i ask this is because the uiRoot never changes its dimensions whereas the screen size changes depending on the screen size of your phone,ipad or whatever device you have
so with this scenario the sprite never actually moves, therefore i could never make an app that will work on all devices
Unity UI works straight out the bag with no problems


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #1 on: December 07, 2016, 06:44:59 AM »
When you target UIRoot, it just falls through to targeting the camera used to draw the UI. In your case the game view is hidden, and I'm venturing a guess that you're on a mac -- and there is a Unity bug preventing the screen size from being determinable on a retina mac. This is why the purple border is off.

Make sure you're on the latest NGUI. Open NGUITools.cs, go to line 1907 and add [System.NonSerialized] in front of it:
  1. [System.NonSerialized] static Vector2 mGameSize = Vector2.one;

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #2 on: December 07, 2016, 02:06:26 PM »
working perfectly thank you


When you target UIRoot, it just falls through to targeting the camera used to draw the UI. In your case the game view is hidden, and I'm venturing a guess that you're on a mac -- and there is a Unity bug preventing the screen size from being determinable on a retina mac. This is why the purple border is off.

Make sure you're on the latest NGUI. Open NGUITools.cs, go to line 1907 and add [System.NonSerialized] in front of it:
  1. [System.NonSerialized] static Vector2 mGameSize = Vector2.one;

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #3 on: December 07, 2016, 02:21:24 PM »
that victory was short lived as soon as i press play to test, it goes straight back to a huge canvas when i press stop it stays large any more ideas please its completely unusable at the moment because i can't build my UI

thank you for the help received

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #4 on: December 08, 2016, 01:50:44 PM »
does anyone have a permanent fix for this issue basically the fix @ArenMook gave works until you press play then it goes straight back to how it was

thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #5 on: December 08, 2016, 07:19:37 PM »
I wish I didn't have to work around this silly Unity bug...

Open up NGUITOols.cs, and got o line 1957:
  1. #if UNITY_EDITOR_OSX
  2.                                         // There seems to be a Unity 5.4 bug that returns invalid screen size when the mouse is clicked (wtf?) on OSX
  3.                                         if (mGameSize.x == 1f && mGameSize.y == 1f) mGameSize = s_GetSizeOfMainGameView();
  4. #else
  5.                                         mGameSize = s_GetSizeOfMainGameView();
  6. #endif
Try removing the #if UNITY_EDITOR_OSX section so it always retrieves the game view size like on other platforms. This was broken on OSX whith Unity 5.4 and only on retina screen devices. Try playing around with stuff there and try printing the returned value to see what it prints.

From what I remember, it was working fine until a user pressed a button, at which point the function returned a completely different value from before, which is why I #ifdef'd it out.

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #6 on: December 09, 2016, 01:58:00 PM »
that seems to be doing the trick so far thanks for the help

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #7 on: December 10, 2016, 09:53:18 AM »
So removing the #ifdef section, leaving just mGameSize = s_GetSizeOfMainGameView(); makes it work fine, even when you hit Play and click some button?

Eze

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #8 on: December 12, 2016, 11:07:45 AM »
I had exact same issue when I upgraded to Unity 5.5.0f3 with NGUI 3.11.0, and I can confirm that removing #ifdef section from NGUITools.cs fixed this issue.

OS: macOS 10.12.2 (with retina display).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #9 on: December 12, 2016, 04:43:04 PM »

Eze

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #10 on: December 13, 2016, 06:12:55 AM »
I upgraded NGUI to the latest release - 3.11.1 and it's working as intended without necessity to change anything in NGUITools.cs.

To be clear, my issue was with UIRoot not adapting to game window when resolution was changed.

clevekim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Why isn't the UI Root the same size as the camera
« Reply #11 on: March 17, 2017, 10:20:24 PM »
I solved this problem.
I use camera for anchor.