Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: theprojectabot on March 08, 2013, 05:40:10 PM

Title: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: theprojectabot on March 08, 2013, 05:40:10 PM
I instantiate a prefab that has a position of 0,0,0 I then parent that prefab to a container prefab.  This container prefab has a UIGrid attached to it.  At the end of instantiating all my prefabs I: uiGrid.repositionNow = true;

This works fine unitl I hover over a button.  It then send the prefab child off into a totally random position.  I found by turning off the UIButtonOffset script I no longer had these issues under UIGrid.

Steps:
Instantiate UIButtonprefab that has UIButtonOffset attached. 
Child it to a UIGrid Gameobject
call repositionNow
hover mouse over button and watch it disapear.
Title: Re: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: theprojectabot on March 08, 2013, 06:53:21 PM
perhaps I am exposing a problem in my own UI setup....
If I call ResetPosition on my draggable panel it gets set to:  x= -1084590, instead of 0. I wonder where this random number is coming from that the draggable panel thinks is its top right...  all parents are 0,0,0 in for their positions except for the UI root which I set to -1426 on x so that it wont be in my 3d camera.

Any ideas folks?

btw that random number was the same x I got when I had button offset on..
Also I am finding that unless I set the localScale of my buttons in code right after instantiation they come out as 735,735,735 scale instead of 1,1,1.

Ideas?
Title: Re: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: theprojectabot on March 08, 2013, 07:41:19 PM
Ok after looking into this I think I see where there are weird values being populated... but I dont know why they are there:

in SetDragAmount I see that left and right = 1096121  these numbers are calculated by the b.min + hx  which comes from the clipRange of the mPanel.

This all comes from a calcualted Bounds  from the mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans); on Line 145 in UIDraggablePanel...
Is this because I have large wigets pixel dimensions of x wide:1154 and 10 of them? plus grid spacing? 

yeah it just seems my bounds are way way off.  And I dont know why...
Title: Re: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: ArenMook on March 08, 2013, 08:40:41 PM
Use NGUITools.AddChild to instantiate objects.
Title: Re: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: theprojectabot on March 08, 2013, 09:00:48 PM
I tried that route and I still have the same problem.
Title: Re: instantiated prefabs with UIButtonOffset freak out when under a UIGrid
Post by: bjennings76 on September 22, 2013, 06:59:37 PM
I've had this same problem when removing buttons from a UIGrid and then repositioning the remaining buttons.

Each button will slide back to its original position on mouse over, leaving a hole in the list and acting just plain weird. This is because UIButtonOffset's 'mPos' variable used to tween doesn't get reset when the UIGrid repositions it's children. That position only gets set once at in UIButtonOffset's Start() function.

I see two solutions to the problem:

For me, I didn't need the UIButtonOffset effect, so I've just removed the UIButtonOffset component and my problem is solved.