Author Topic: UIAnchor and UIStretch  (Read 2215 times)

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
UIAnchor and UIStretch
« on: July 22, 2014, 02:48:56 AM »
I have a question about these two deprecated components. I'm working on mobile and I really like these two components because it seems to me that it's much easier with them to create a button that is padded 10% from the right of the screen and stretched 40% of the screen width. With the new anchor system shown in the tutorials it's not really clear to me how to do that quickly and there's all those pixels values that I don't really need because my gui has to work on many different devices.

I was wondering if it's not recommended to use UIAnchor and UIStretch for performance reasons and also if there's a way to not have the "run only once" activated. I noticed that if "run only once" is active some of the elements are not placed or stretched correctly when I switch between views.
If "run only once" is active I notice in the profiler that the performance is pretty bad sometimes and that a lot of CPU is spent in the anchors and stretch updates functions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor and UIStretch
« Reply #1 on: July 22, 2014, 09:12:47 PM »
Use the layout system. If you want it to be 10% from the right side of the screen and have the width of 40%, then you'd set the Left anchor to be Center (which is == 0.5) and right anchor to be Custom -- 0.9 (90% toward the right).

If you don't want it to update frequently, change its update to be OnEnable.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: UIAnchor and UIStretch
« Reply #2 on: July 24, 2014, 03:29:31 AM »
ok I'll try it out. I was used to the old anchor and stretch component and this new system is a bit counterintuitive for me. That said, using the old anchor and stretch is it really bad for performance at the moment?

And using OnEnable in the new system is it going to work fine when many elements have to get positioned depending on other elements positions? If all elements position themselves in OnEnable (which is called for all components at the same time) how can you guarantee that the anchor target is already at the correct position when OnEnable is called?
This problem was happening when the gui was built in the editor with the iPad settings and then the game is built and run on an iPhone 5. In this case the gui will adapt at start but I always had some components in the wrong position if I did check the only run once tick box.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor and UIStretch
« Reply #3 on: July 25, 2014, 01:02:15 AM »
The new layout system updates things in order. Each anchor that relies on another makes sure to update the other one first.