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 Mjhurtado1 · Jan 23, 2014 at 06:10 AM · c#nullreferenceexceptionstrange

Strange Problem: NullReferenceException

Here is what it says

"NullReferenceException: Object reference not set to an instance of an object at ItemCounter.Update () [0x0001c] in C:\Users\Documents\3dPlatformer\Assets\C# Scripts\ItemCounter.cs:16 (Filename: C Line: 0)"

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

I know what this means, I have the game objects set in the inspector.

This error only occurs in the Built Standalone version.

There is no error when in the Unity3d Editor Player.

If anyone can help with this that would be amazing! Thanks

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ItemCounter : MonoBehaviour {
 
     private bool finished = false;
     public int maxItems;
 
     public GameObject enableThisObject;
     public GameObject disableThisObject;
 
     public int currentItems = 0;
     
 
     void Update(){
         if(currentItems >= maxItems && finished == false){
             enableThisObject.SetActive(true);
             disableThisObject.SetActive(false);
             finished = true;
         }
     }
 
     void OnTriggerEnter(Collider items){
         if(items.gameObject.name == "item"){
             currentItems += 1;
         }
 
     }
 
     void OnTriggerExit(Collider leave){
         if (leave.gameObject.name == "item") {
             currentItems -= 1;
         }
     }
 
 }
Comment
Add comment · Show 14
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 Mjhurtado1 · Jan 26, 2014 at 12:18 AM 0
Share

No one can answer this one?

avatar image Murkas · Jan 26, 2014 at 12:30 AM 1
Share

which line exactly is line 16? In your posted code line 16 is void Update(). I don't think it references this line.

avatar image Mjhurtado1 · Jan 26, 2014 at 03:38 AM 0
Share

enableThisObject.SetActive(true); is line 16 I think

avatar image Invertex · Jan 26, 2014 at 03:43 AM 0
Share

Did you save the scene before compiling?

avatar image Mjhurtado1 · Jan 26, 2014 at 06:13 AM 0
Share

Yes, I saved, I restarted and all that stuff but unfortunately no luck.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by naveen_pambi · Jan 27, 2014 at 12:47 PM

if(currentItems >= maxItems && finished == false){

         ***if(enableThisObject != null && enableThisObject != null)***
         {
              enableThisObject.SetActive(true);
              enableThisObject.SetActive(false);
              finished = true;
         }
    }

try with adding one more condition for checking null. like above

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 Murkas · Jan 27, 2014 at 02:40 PM 0
Share

But that is not solving the problem. It is just not doing, what it should do. If he assigned the gameobjects in the Inspector, then they should not be null, but exactly that is happening.

avatar image naveen_pambi · Jan 28, 2014 at 04:51 AM 0
Share

Error is NullReferenceException means some of the gameobjects is null. $$anonymous$$ay be he assigning the gameobjects in the Inspector after Update is called. So, above condition helps in the same.

avatar image Murkas · Jan 28, 2014 at 02:50 PM 0
Share

I know, what NullReferenceExceptions means, but he is not able to assign the objects in the Inspector while on standalone. I understood, that he assigned the gameobjects, then tried it in the editor (and it worked) and then he built it and it did'nt work in standalone. So a) he used something, like Application.IsEditor, or b) he did something different from what he described or c) The engine has a bug. I personally think it is b.

avatar image
0

Answer by Quonce · Dec 27, 2019 at 01:58 PM

I think I found a solution - do not use "incremental GC"

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

25 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

Related Questions

RaycastHit2D not interacting with tags 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Changing an objects background image on hover. 1 Answer

NullReferenceException - Maze Generator Script 1 Answer


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