Author Topic: UIScrollPanel & mPanel  (Read 4965 times)

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
UIScrollPanel & mPanel
« on: April 20, 2016, 10:52:20 AM »
the function UIScrollPanel.RestrictWithinBounds() uses mPanel before its initialized, normally mPanel is inited in awake but in some circumstances RestrictWithinBounds is called before that. Can you add if (mPanel == null) mPanel = GetComponent<UIPanel>(); before mpanel is used in that method?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollPanel & mPanel
« Reply #1 on: April 20, 2016, 04:59:47 PM »
What would be the case of it being called before Awake()? What's calling it from another Awake()? That's the bug here. Nothing should be calling it from an Awake().

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: UIScrollPanel & mPanel
« Reply #2 on: April 22, 2016, 06:32:59 AM »
it's getting called from OnEnable in a parent object script.

why wouldn't you want to add a null check? there's null checks for mPanel in the same script - presumably there are other times when mPanel is null and you don't want an exception.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollPanel & mPanel
« Reply #3 on: April 25, 2016, 12:28:10 PM »
OnEnable is called right after Awake as well. This happens as soon as the component is added to a game object, and before any properties can be set. So for example this:
  1. UIPanel p = gameObject.AddComponent<UIPanel>();
  2. // Awake / OnEnable runs immediately before the statement above returns
...means that the entire AddComponent() call will not even return until after Awake and OnEnable have been executed. What script calls it in OnEnable? If it's NGUI, then that too should be fixed.