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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Zexanima · Mar 31, 2014 at 01:19 AM · c#objectnull

What is the reason for this NullReferenceException?

None of my other Objects seem to be able to reference the script ItemManager, every time I call for a static variable from it, it returns null.

World - World

Player - alt text

Here is the first (of many) places I get the error:

     NullReferenceException: Object reference not set to an instance of an object
     Inventory.Start () (at Assets/Scripts/Player/Inventory.cs:58

     Line58: ItemSlot temp = new ItemSlot(ItemManager.EMPTY.ShallowCopy());

I think it has to do with the static variable EMPTY, however I believe I have it setup correctly:

 public static Item EMPTY;
     public static Item STONE;
     public static Item GRASS;
     public static Item BRICK;
     
     //************************************
 
     // Use this for initialization
 
     void Start () {
         Debug.Log ("Initalized");
         guiCon = gameObject.GetComponent ("GUIController") as GUIController;
         soundMan = gameObject.GetComponent ("SoundManager") as SoundManager;
         
         // *** Set new ***
         
         // *** Initialize Item *** 
         EMPTY = new Item("", 0 , 64, new Rect(0.25f,0.75f, 0.25f,0.25f), itemIcons, Item.ItemType.Empty,"DefaultItem");
             // MORE CODE AFTER...
        


ss (2014-03-30 at 06.09.45).png (15.8 kB)
ss (2014-03-30 at 06.11.40).png (17.3 kB)
Comment
Add comment · Show 3
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 Zexanima · Mar 30, 2014 at 11:28 PM 0
Share

I can eli$$anonymous$$ate most the null reference exceptions to the Item$$anonymous$$anager script by setting script execution order, but it doesn't fix them all so I think there is some other issue.

avatar image getyour411 · Mar 31, 2014 at 01:35 AM 1
Share

Try moving the E$$anonymous$$PTY = ... stuff into Awake()

avatar image Zexanima · Mar 31, 2014 at 02:08 AM 0
Share

@getyour411 That didn't work, same error.

1 Reply

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

Answer by Zexanima · Mar 31, 2014 at 04:58 AM

I saved, reopened Unity, and it was suddenly working. I didn't even change anything. Don't know what was wrong.

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

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Audio Play Once 2 Answers

How do you position an object relative to the camera? 0 Answers

Does Scripting Jump exist? (How To use/write goto) 3 Answers

Destroy only selected object 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