Author Topic: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()  (Read 3964 times)

schneidb

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 2
  • Posts: 24
    • View Profile
On iOS, I'm getting NullReferenceExceptions when I attempt to do UIButton.GetScreenRect()

It looks like UICamera.currentCamera is null on line 10 of NGUIExtensions.cs

I know I can just check for null, but if you have any suggestions for how I should/could make a real fix, that'd be great.

This does not happen in the Unity Editor.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
What's NGUIExtensions? There is no such file in NGUI. There is NGUIEditorExtensions, and line 10 is just a comment before the static class itself.

schneidb

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 2
  • Posts: 24
    • View Profile
Sorry, this was my mistake.  NGUIExtensions is my colleague's class.  I was just too tired at the time to notice.  Having said that, we still can't figure out why UICamera.currentCamera is null in an Update method only in iOS. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
All 'current' references in NGUI are valid only during specific callbacks. In case of UICamera.currentCamera it's set for NGUI's events such as OnClick, OnPress, OnHover, etc. It's only valid during those events.

schneidb

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 2
  • Posts: 24
    • View Profile
Thanks for the information.