Author Topic: [SOLVED] BUG: Widgets not redrawn when parent translated  (Read 10351 times)

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
[SOLVED] BUG: Widgets not redrawn when parent translated
« on: February 26, 2013, 05:49:35 PM »
I've created a special table that reuses cell-objects (much like in the Android or iOS api), which basically instantiates as many cell-objects as needed for all cells currently within screen, and then reuses cells going out of screen for cells going in on screen (simplified).

So without getting to complicated with details, I've found after a whole day trying that it comes down to the following to recreate the bug(?):
  • Instantiate a prefab (GameObject of scale (1,1,1) that holds multiple widgets) using AddChild or any likewise method for that matter
  • Reparent the instantiated gameObject to empty (scale (1,1,1)) gameObjectA under your panel (done automatically if you use AddChild ofc.)
  • Change the sprite of any UISprite-widget parented to the instantiated gameObject
  • Reparent the instantiated gameObject again to empty (scale (1,1,1)) gameObjectB under the same panel

Doing this will work fine until you try to move the instantiated objects PARENT which in this case is gameObjectB. The instantiated object will move (gizmos showing how widgets move along), but the actual graphic will stay in the same place... If I (in the editor) reparent the instantiated object to any other gameObject (for example gameObjectA) it works fine, but if a place it back to gameObjectB again it's still not working. To make it work again, I'll have to disable and enable the responsible UIPanel.
As a sidenote, it WILL WORK if you skip the first parenting to gameObjectA (step 2).

The above order is required for the generic nature of the table, since reusable objects will be instantiated, and then reparented around depending on if they are visible or not. Inbetween this reparanting the client (table-handler-script) will be requested to setup a specific cell about to be visible, which is where the actual sprite-change occures. So basically, a short "well then don't do it this way"-answer won't really help me (and I think this bug-or-whatever should not be ignored). :)

See attached image for this epic randomness!

As you can see, all the white bounds are the widgets in the CORRECT position, however the actual graphic is not redrawn... I've tried to understand all that happens in UIPanel, but writing this topic seemed easier! :)


EDIT: For all interested, the bug was found and will be available in the next update. Here is the fix until then:

Michael Lyashenko:
Thank you for the simple repro case! I found the issue. 2.3.5 will have the fix. You can fix it locally by opening up UIPanel and replacing AddTransform function with this:

  1.     UINode AddTransform (Transform t)
  2.     {
  3.         UINode node = null;
  4.         UINode retVal = null;
  5.  
  6.         // Add transforms all the way up to the panel
  7.         while (t != null && t != cachedTransform)
  8.         {
  9. #if UNITY_FLASH
  10.             if (mChildren.TryGetValue(t, out node))
  11.             {
  12.                 if (retVal == null)
  13.                     retVal = node;
  14.             }
  15. #else
  16.             if (mChildren.Contains(t))
  17.             {
  18.                 if (retVal == null)
  19.                     retVal = (UINode)mChildren[t];
  20.             }
  21. #endif
  22.             else
  23.             {
  24.                 // The node is not yet managed -- add it to the list
  25.                 node = new UINode(t);
  26.                 if (retVal == null) retVal = node;
  27.                 mChildren.Add(t, node);
  28.             }
  29.             t = t.parent;
  30.         }
  31.         return retVal;
  32.      }
  33.  
« Last Edit: March 05, 2013, 05:13:56 AM by helmesjo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #1 on: February 26, 2013, 07:38:23 PM »
After you reparent an object, you need to inform that object that it has been reparented. Look at what I do in the drag & drop example.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #2 on: February 27, 2013, 05:23:48 AM »
I checked your example out and changed my code accordingly, but the issue still remains. Note: This only happens when i change the spriteName! If I just change parent around, all is fine (even without CheckParent()).

Basically this is what my example looks like to reproduce the bug:
  1.     if(Input.GetKeyUp(KeyCode.S)){
  2.         //Simple buttonScript that holds reference to one of the UISprites
  3.                 OverviewButton button = NGUITools.AddChild(gameObject, testPrefab.gameObject).GetComponent<OverviewButton>();
  4.                
  5.                 button.m_Background.spriteName = "gui_tableitem_background_middle";
  6.                
  7.         GameObject derp = NGUITools.AddChild(gameObject);
  8.                 button.transform.parent = derp.transform;
  9.                
  10.         //Broadcast message to all widgets under the new parent (also tried to broadcast from UIRoot or the instantiated object, same issue)
  11.                 derp.BroadcastMessage("CheckParent", SendMessageOptions.DontRequireReceiver);
  12.      }
  13.  

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #3 on: February 28, 2013, 05:36:02 AM »
So, had any time to look into this? This is for a project to a client, so it's somewhat urgent :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #4 on: February 28, 2013, 08:48:22 AM »
All I can offer to you is the "works fine on my machine", so unfortunately you will need to debug it yourself. Make sure your panels are not static, and if you can create a very tiny repro case using a new scene and NGUI's default assets, send it to support at tasharen.com

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #5 on: March 01, 2013, 05:42:23 AM »
Created a new project, did the same testcase, found the same bug. I've send it to support@tasharen.com with the same title as this thread. Just open, start, and you should instantly see the bug.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #6 on: March 04, 2013, 05:33:46 AM »
Don't want to be annoying, but any progress? An automated answer or whatever whould be nice, so one know that the email was received atleast! (:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #7 on: March 04, 2013, 12:12:26 PM »
Sorry, your email was received, but I am super swamped right now and haven't gotten around to it yet.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: BUG: Widgets not redrawn when parent translated
« Reply #8 on: March 05, 2013, 03:32:16 AM »
NP mate, got the answer this morning :)
« Last Edit: March 05, 2013, 05:13:17 AM by helmesjo »

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: [SOLVED] BUG: Widgets not redrawn when parent translated
« Reply #9 on: March 15, 2013, 01:02:34 PM »
Dude, did you forget to include this in the update? Experienced the same bug again, and saw that UIPanel was missing the changes you mailed me (see first post)... :)
« Last Edit: March 15, 2013, 06:35:43 PM by helmesjo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [SOLVED] BUG: Widgets not redrawn when parent translated
« Reply #10 on: March 16, 2013, 10:52:26 AM »
No, it's there. You sure you have 2.3.6?

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: [SOLVED] BUG: Widgets not redrawn when parent translated
« Reply #11 on: March 18, 2013, 03:53:18 AM »
You are absolutely right sir! Apparantly Unity doesn't replace your current asset if it's not placed in the root (I used an "External"-folder)... So it found which files where changed, but didn't actually replace the old ones. -.-
My bad!
« Last Edit: March 19, 2013, 05:17:33 AM by helmesjo »