Author Topic: Objects "Jumping" to place  (Read 4424 times)

Dalediko

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Objects "Jumping" to place
« on: June 02, 2014, 10:32:53 AM »
Hey,

I've created a few quite complex NGUI layouts (NGUI 3.6.0).
I've noticed that when the scene starts, the objects don't appear right in place -
but seem to appear elsewhere, and "jump" into place in some quick animation.

Is there a way to avoid that, and make them appear immediately in their correct position?

TNX

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Objects "Jumping" to place
« Reply #1 on: June 02, 2014, 11:25:05 PM »
Depends on what's causing them to move. Are you using anchors? Most common cause of something like this would be hiding your game view behind your scene view, or using Maximize on Play.

Dalediko

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Objects "Jumping" to place
« Reply #2 on: June 03, 2014, 03:18:43 PM »
Yes, of course, I'm using anchors heavily, to position all my objects
relatively to the screen and to each other.

But their position is only set once, on startup, and then it doesn't change -
so I expected all the calculations to be performed once, on startup, and having
all the objects appear immediately at their correct position...

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Objects "Jumping" to place
« Reply #3 on: June 03, 2014, 04:54:07 PM »
This is an ongoing issue that was even more prevalent with the old UIAnchor system.

If you create your things in an Update, it won't position correctly until next update. Essentially you need to have a force refresh of the anchor immediately, which potentially will make everything be redrawn again that. I think we made something for that, I'll have to check when I get back in to work.

Dalediko

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Objects "Jumping" to place
« Reply #4 on: June 03, 2014, 05:38:00 PM »
Thanks!
I'm waiting for updates.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Objects "Jumping" to place
« Reply #5 on: June 04, 2014, 01:38:38 AM »
Dynamic instantiation in Update requires certain things to occur if you want proper results right away.
  1.                 Execute<UIWidget>("Start", root);
  2.                 Execute<UIPanel>("Start", root);
  3.                 Execute<UIWidget>("Update", root);
  4.                 Execute<UIPanel>("Update", root);
  5.                 Execute<UIPanel>("LateUpdate", root);
So first, start the widgets, then the panels. Then update the widgets, and update the panels. Lastly, LateUpdate the panels to create the draw calls. The Execute function looks like this:
  1.         static void Execute<T> (string funcName, GameObject root) where T : Component
  2.         {
  3.                 T[] comps = root.GetComponents<T>();
  4.  
  5.                 foreach (T comp in comps)
  6.                 {
  7.                         MethodInfo method = comp.GetType().GetMethod(funcName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  8.                         if (method != null) method.Invoke(comp, null);
  9.                 }
  10.  
  11.                 Transform t = root.transform;
  12.                 for (int i = 0, imax = t.childCount; i < imax; ++i)
  13.                         Execute<T>(funcName, t.GetChild(i).gameObject);
  14.         }