Author Topic: NullReferenceException after running  (Read 16183 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NullReferenceException after running
« Reply #15 on: November 04, 2014, 10:45:50 AM »
What does NGUITools.screenSize report?

I'm guessing this is where the change lies. Have a look at what's different in terms of returned values inside this function on the two versions of Unity.

juggernate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: NullReferenceException after running
« Reply #16 on: November 04, 2014, 02:35:39 PM »
They report the same values in both p2 and p3. But I'm printing NGUITools.screenSize to console at runtime, which is when the anchors look fine. I'm not sure how to debug.log when play is stopped?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NullReferenceException after running
« Reply #17 on: November 06, 2014, 01:09:09 AM »
I just gave the latest Pro version a try on the latest Unity 5 beta, and everything works as expected. All anchors work. To do a debug.log at edit time you can create a function like this:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.     [ContextMenu("Execute")]
  6.     void Execute () { Debug.Log("Hello world!"); }
  7. }
You can then right-click the script in inspector (after attaching it to some object) and choosing "Execute" from the drop-down list.

juggernate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: NullReferenceException after running
« Reply #18 on: November 06, 2014, 02:22:34 PM »
Ah, thanks. I tried that and NGUITools.screenSize reports the same values when the anchors look correct during play or when the anchors break while stopped

juggernate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: NullReferenceException after running
« Reply #19 on: November 07, 2014, 08:51:29 PM »
Thanks for the workaround/fix in 3.7.6!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NullReferenceException after running
« Reply #20 on: November 09, 2014, 08:58:27 PM »
Unity broke OnValidate in the last few versions, it's no longer affected by the script execution order -- which is why the anchoring issues started happening. I added a work-around for this bug in 3.7.6 so it should work as expected again. In the meantime I also submitted a bug to Unity -- #646217.

dannypb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: NullReferenceException after running
« Reply #21 on: January 09, 2015, 11:32:10 AM »
I had the strangest thing happen with this.  I went to change the code line 623 as above and when I saved it in monodevelop, it deleted a number of lines of code.  I undid the changes and tried to save what was there and it did it again.  I tried this a few times to no avail.  Every time monodevelop would delete about 800 or so lines of code. 

I pulled it up in textpad and restored the file from a clipboard copy I made and saved it in it's original format, thinking I would test it first then make the edit on line 623 as above.  When I tested it with the original code the error was gone. 

I wonder if there were some special characters in the script that gave monodevelop and unity problems.  Now that I saved it in an editor that stripped those out, everything works fine.