Author Topic: Yes, my widget is a child of the panel  (Read 4512 times)

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Yes, my widget is a child of the panel
« on: September 04, 2014, 04:52:13 PM »
Hi,

my hierarchy is built like this:

"Panel" (UIPanel with clipping + UIScrollView)
+ "Sprite" (UIDragScollView + Box Collider + UIWidget)
++ "Stuff 1"
++ "Stuff 2"
++ ...

Thing is, NGUI complains with:

Quote
Widgets and panels should not be on the same object! Widget must be a child of the panel.
UnityEngine.Debug:LogError(Object, Object)
UIWidget:OnStart() (at Assets/NGUI/Scripts/Internal/UIWidget.cs:1042)
UIRect:Start() (at Assets/NGUI/Scripts/Internal/UIRect.cs:430)


But isn't it? Or does UIDragScrollView count as a Panel?!

EDIT:

Got it. I have it that when I click the "Stuff" buttons, I use a manual call to SpringPanel.Begin() to position the "Sprite". In that moment, a UIPanel gets added and NGUI complains.

When I use a manual  transform.position = newPos, there's no problem.

NGUI misbehavior or should I set my stuff up differently?
« Last Edit: September 04, 2014, 04:57:26 PM by Bradamante3D »
#301224014, #301432336, #302399130

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #1 on: September 05, 2014, 02:50:58 AM »
It sounds correct. This only happens if a widget (label or sprite) is on the same object as a UIPanel.  You can look through all your Panels by searching for t:UIPanel and see if any of them has a widget on it as well.

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #2 on: September 05, 2014, 08:51:10 AM »
Well, it has, no secret, see the Hierarchy in my first post.

I am using the UIWidget to give the scrolled content, which the elements are parented to, a certain size (1920x1440 in this case). Is there a different way to achieve this?
#301224014, #301432336, #302399130

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #3 on: September 05, 2014, 11:31:51 AM »
The hierarchy you wrote says nothing about widgets and panels being on the same gameobject. UIDragScrollView does not count as a panel.

The intermediate "Sprite" is fine, it looks to be correct.

Which object does the LogError point to when you click it in the console?

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #4 on: September 05, 2014, 11:40:35 AM »
I understand I should have been more clearer.

As described in my edit, SpringPanel.Begin() adds a UIPanel to the "Sprite" GameObject. At that moment, NGUI complains, since now a UIPanel and a UIWidget are on the same GO.

Should I introduce another layer of hierarchy? Am I totally off?

The hierarchy you wrote says nothing about widgets and panels being on the same gameobject.
#301224014, #301432336, #302399130

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #5 on: September 05, 2014, 01:28:26 PM »
You should not be using SpringPanel.Begin on a game object. It should only be used on scroll views. I don't know why you are trying to use it on a non-panel...

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: Yes, my widget is a child of the panel
« Reply #6 on: September 06, 2014, 06:15:47 PM »
Alright, got it. Basically I used SpringPanel.Begin to achieve a behavior that actually UICenterOnChild is for. It works now.

SpringPanel.Begin however did have the same effect, only that Unity throws an error. I used it like: SpringPanel.Begin ( "Sprite" ) - see the first post. "Sprite" is the holder GameObject of the content objects, with the UIDragScrollView on it.
#301224014, #301432336, #302399130