Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by jpenca · Jan 18, 2012 at 04:55 PM · androidnullreferenceexception

NullReference in Start() or Awake() when testing on Android device, works fine in Editor

i'm getting a weird null reference exception when i debug my app on device (Asus Transformer Prime).

This happens in app initialization, both in Start() and Awake(). The Transform is being assigned in the Inspector, and when launching the app in the Editor it works fine, i get a reference to the Transform as expected, while on the device i get a null reference.

 public Transform weirdObject;
 
 void Awake()
 {
     if(this.weirdObject == null) Debug.Log("meh. null.");
     else Debug.Log("yea it's not null");
 }
Comment
Add comment · Show 5
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 jahroy · Jan 18, 2012 at 07:03 PM 0
Share

There is zero chance of anybody deter$$anonymous$$ing what is wrong based on the code you've included. All this does is check for null. The problem has to be elsewhere.

avatar image jpenca · Jan 18, 2012 at 08:06 PM 0
Share

i know the code snippet is not the problem, thanks. the problem is described in the text above the code snippet.

with it i wanted to enforce the point that this happens on app initialization, before anything complicated happens on my side, so it should be deter$$anonymous$$istic? in fact, it is, i seem to get this consistently on each launch on the device.

maybe someone here has had a similar issue. what could cause the difference in execution between the editor and the device?

avatar image Tyler 10 · Jan 18, 2012 at 10:13 PM 0
Share

I know from the unity docs that assets aren't readily available on the first level on android devices. Try making a level with nothing in it except a script that loads the level you are having trouble with. $$anonymous$$ake that level load first. Just a suggestion.

avatar image jpenca · Jan 19, 2012 at 01:14 PM 0
Share

ah thanks. this doesn't solve the problem on the device, but when i start the launcher level in the editor, i now get the same null reference from my problematic level within the editor. should be easier to debug at least!

avatar image djarcas · Jul 06, 2013 at 01:18 PM 0
Share

Did you solve this? I'm getting the same issue in Window; the game runs perfectly well inside the Editor, but when I make a build and run it, huge swathes (but not all) of the inspector values appear to be null.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by silva_raptor · Jun 30, 2013 at 02:37 PM

I had this exact problem and I couldn't find an answer. The NullReferenceException happened only on Android and iOS, while it was working fine on the editor. The script wasn't even able to find anything using GameObject.Find(). It happened only in one of the objects in the scene, so my "dirt" solution was to create an empty gameobject with a singleton script linked to all the needed references, and use it as a "helper" of my problematic gameobject.

I think that this is some kind of strange bug of unity.

Comment
Add comment · 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
0

Answer by bajtek · Dec 20, 2017 at 07:41 PM

Hi, It's a topic from long past but I had the same problem and I found solution for it in my case. I used SQLite and I added one table to database. When I copied .db file from Assets to StreaminAssets directory it still didn't work. The solution for it was changing version of build in Edit>Project Settings>Player from 1.0 to 1.1. I don't know why but it works.

Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

NullReferenceException: Object reference not set to an instance of an object 3 Answers

Unity IAP Button: NullReferenceException: Object reference not set to an instance of an object 1 Answer

Script works on some objects and not others, also varies between scenes... 0 Answers

Building for android freezes unity editor 2 Answers

Unity3D Android NullReferenceException for class properties during using Input.location.lastData 2 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