Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: schneidb on May 29, 2014, 03:43:41 PM

Title: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()
Post by: schneidb on May 29, 2014, 03:43:41 PM
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.
Title: Re: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()
Post by: ArenMook on May 30, 2014, 02:09:19 PM
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.
Title: Re: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()
Post by: schneidb on May 31, 2014, 11:30:08 AM
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. 
Title: Re: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()
Post by: ArenMook on May 31, 2014, 01:04:19 PM
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.
Title: Re: NullReferenceException for UiCamera.currentCamera when calling GetScreenRect()
Post by: schneidb on June 02, 2014, 02:09:45 PM
Thanks for the information.