Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by esitoinatteso · Nov 10, 2015 at 08:43 PM · buildbuild-errornullreferenceexception

Unity Build nullReference, but editor sees through it!

Hi there, sorry to bother but this kind of errors are new to me because I've been coding mainly inside the editor!

It seems that 1 line in my Awake() returns != null when in editor, and == null once built.

This is the line, though it doesn't help too much per se:

         //Outputting
         textBehaviour.LinesToPrint(myDialogue.NpcLines[0]);

textBehaviour is an instance of one of my Classes, it just has to print a string.

I believe that, since the development build says nullReference and not Index out of Range, the problem is that instance itself.

Could it be that myDialogue has something to do with this too? That maybe the error derives from a null parameter?

In the editor I did tweaked scripts execution order to fit my needs... maybe in builds that's a bad thing?

I'm trying to build for mac. I know I've provided scarce infos on this, but I don't know what to look for... I could really use some help.

I've looked previous similar questions but I can't understand how it's possible that the same variable works if in editor and screws up if in build!

Thanks :D

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Statement · Nov 10, 2015 at 08:53 PM

What is null?

textBehaviour or myDialogue?

If you can't tell, figure it out. Attach a debugger or call print or Debug.Log/Warning/Error.

 void Awake()
 {
     LogNullError(textBehaviour, "textBehaviour");
     LogNullError(myDialogue, "myDialogue");
     textBehaviour.LinesToPrint(myDialogue.NpcLines[0]);
 }
 
 void LogNullError(object o, string name)
 {
     if (o == null)
         Debug.LogErrorFormat(this, "The variable {0} is null", name);
 }

Then figure out where that object is set. Maybe it's a result from a file load? Maybe that part behave different depending on the location of your executable or operating system? And so on.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image esitoinatteso · Nov 10, 2015 at 09:56 PM 0
Share

Thanks a lot! I'll use those calls and check it out.

Yes, there's a bunch of stuff working to provide that line; the current class asks textBehaviour to grab a string from another class instance.

Since serialization is involved I believe the error could derive from there... although I made sure to use strings like Application.persistentDataPath to avoid wrong path issues...

Now that I've tested it, it says that the third instance is ok but fails to compile and return the needed string.

That is: textBehaviour is ok, myDialogue is ok, myDialogue.NpcLines[0] doesn't exist ( yet).

Since I know it exists because the editor debugs properly, what should I do to make sure my scripts run in the proper order also in the build?

Thanks a lot for helping me!

avatar image Statement esitoinatteso · Nov 10, 2015 at 10:25 PM 0
Share

Just follow the code to where myDialogue.NpcLines is assigned, or where NpcLines[0] is assigned, if that is what is null. Trail the flow of the program backward and inspect key code junctions to see what caused it to be null. (Was it assigned null, or was it never assigned anything? Why? And so you iterate like that to figure out the source. It makes no sense to stop "half way" between an assignment and the failure, just to be clear. It only makes sense to test the locations where a value is assigned (or test if that code was never run in the first place))

avatar image esitoinatteso · Nov 10, 2015 at 10:28 PM 0
Share

I've managed to solve the initial problem but now I've found out that the build can't serialize files to mac directories.

I'll see how that goes and if needed I'll open a new question!

By the way, it wasn't about script orders, it was about a static reference that in build runtime was not as trustworthy as it seemed in editor.

Thanks again!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceException after build 1 Answer

Can't return KeyCode in build 0 Answers

CommandInvokationFailure: Failed to re-package resources. Tried various remedies Please help... 0 Answers

compareTag function not working in build version 0 Answers

Can't "build and run". Can only use the "build "option 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges