Author Topic: New Anchor system doesn't work on mobile (but does on PC) [SOLVED]  (Read 2050 times)

thePostFuturist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
'lo,

As the title states, new anchoring system + "fixed size" option on UIRoot respects the positioning of the widgets (sprite + buttons in my case). Upon compiling on an iPad 3 and iPhone 5, the anchors will only align correctly if the aspect ratio of the camera has been set to it's respecting dimensions. For example, if I choose 16:9 in the Game View dropdown, my UI will scale and position properly on the iPhone 5, but will go out of bounds on the 4:3 ratio on the iPad.

Seems that the camera's aspect ratio is not being updated upon compilation, anyone more clever than I (ArenMook?) can give me a clue on how to solve this?
« Last Edit: August 19, 2014, 07:13:42 PM by thePostFuturist »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New Anchor system doesn't work on mobile (but does on PC)
« Reply #1 on: August 19, 2014, 11:08:55 AM »
What are anchors set to update in? OnEnable, OnStart, or OnUpdate? What are you anchoring to, panel or camera? Does it work if you hit Play in editor and resize the game window?

thePostFuturist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: New Anchor system doesn't work on mobile (but does on PC)
« Reply #2 on: August 19, 2014, 12:45:11 PM »
Q1: OnStart, OnEnable and OnUpdate have the same problem of improper alignment.

Q2: I'm anchoring to the Panel.

Q3: Well, that depends. This is because I have a tween on the buttons, the value of which I assign dynamically on Awake() to subtract:

  1. void Awake()
  2.         {
  3.                 TweenPosition tween_position = GetComponent<TweenPosition>();
  4.                 Vector3 pos = transform.localPosition;
  5.                 tween_position.from = pos;
  6.                 tween_position.to = new Vector3(pos.x - 150, pos.y, pos.z);
  7.         }


So, I'm assuming all of this happens before the Anchoring method, thus assigning the TweenPosition values to simply whatever they were from the initial aspect ratio. Putting my code in a Start function will break the alignment as well.
« Last Edit: August 19, 2014, 01:41:51 PM by thePostFuturist »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New Anchor system doesn't work on mobile (but does on PC)
« Reply #3 on: August 19, 2014, 01:54:18 PM »
Correct, Awake() always runs before everything else. Awake() is basically the constructor. You should never place code in Awake() that affects other components.

Get rid of your tween to begin with. Just kill it. Use TweenPosition.Begin() to create a new tween in Start() after calling UpdateAnchors():
  1. void Start()
  2. {
  3.     GetComponent<UIRect>().UpdateAnchors();
  4.     Vector3 pos = transform.localPosition;
  5.     TweenPosition.Begin(gameObject, 0.5f, new Vector3(pos.x - 150f, pos.y, pos.z));
  6. }

thePostFuturist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: New Anchor system doesn't work on mobile (but does on PC)
« Reply #4 on: August 19, 2014, 07:09:51 PM »
Ah, great, thanks.