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 SkyArchitect · Feb 24, 2016 at 12:55 PM · unity 5scripting problem

A weird NullReferenceException that would disappear in run-time when I select the gameobject in editor's hierarchy the script attach to.

Hi, I am an Architecturual Gruaduate Student of University of Wisconsin-Milwaukee. Right now I am using an personal version of unity and encounter some scripting/engine problem I can not solve myself and can not find answers from community, and my thesis project is an Unity project! I would be very appreciate if someone can help! Thank you!

Here is the YouTube link to my reproduction of the issue (100% reproducable): Unity NullReferenceException Glitch https://www.youtube.com/watch?v=4TW18FXKn_4

Here is a link to the issue I uploaded to unity. (Case 770803) NullReferenceException on script attached to an instantiated gameobject https://fogbugz.unity3d.com/default.asp?770803_kcs7nic90r3u2q6g

Thank you, guys!

Comment
Add comment · Show 6
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 gjf · Feb 23, 2016 at 11:11 PM 0
Share

those sorts of bugs are usually a result of something uninitialized in your script, not unity's code so it's not appropriate to upload to their bug tracker.

try posting the code of the script causing the error along with the CO$$anonymous$$PLETE error message (including line number info). make sure that you format the code using the 101/010 button so that it's a) readable & b) the line numbers match the error message (so we can help you!)

avatar image SkyArchitect gjf · Feb 25, 2016 at 05:37 AM 0
Share
 public void LoadInventory()
     {
         Debug.Log("Inventory file folder at: " + Application.persistentDataPath);
         for (int i = 0; i < 128; i++)
         {
             if (File.Exists(Application.persistentDataPath + "/PlayerInventory(" + i + ")Info.dat"))
             {
                 BinaryFormatter bf = new BinaryFormatter();
                 FileStream file = File.Open(Application.persistentDataPath + "/PlayerInventory(" + i + ")Info.dat", File$$anonymous$$ode.Open);
                 Inventory data = (Inventory)bf.Deserialize(file);
                 file.Close();
                 Debug.Log("Inventory file Loaded from: " + Application.persistentDataPath + "/PlayerInventory(" + i + ")Info.dat");
 
                 Inventory InventoryToLoad = new Inventory();
                 InventoryToLoad.inventoryID = data.inventoryID;
                 InventoryToLoad.inventoryName = data.inventoryName;
                 InventoryToLoad.slotAmount = data.slotAmount;
                 InventoryToLoad.gearAmount = data.gearAmount;
                 InventoryToLoad.weaponAmount = data.weaponAmount;
                 InventoryToLoad.potionAmount = data.potionAmount;
                 InventoryToLoad.carryweight = data.carryweight;
                 InventoryToLoad.weight = data.weight;
 
                 InventoryToLoad.query_amount = data.query_amount;
                 InventoryToLoad.query_dura = data.query_dura;
                 InventoryToLoad.query_equip = data.query_equip;
                 InventoryToLoad.query_id = data.query_id;
                 InventoryToLoad.query_slot = data.query_slot;
 
                 StartPanel(InventoryToLoad);
             }
         }
         for (int i = 0; i < 128; i++)       //check for the condition that no project exist
         {
             if (!File.Exists(Application.persistentDataPath + "/PlayerInventory(" + i + ")Info.dat"))
             {
                 if (i == 127)
                 {
                     Inventory InventoryToLoad = new Inventory();
                     InventoryToLoad.inventoryID = 0;
                     InventoryToLoad.inventoryName = "$$anonymous$$y Inventory";
                     StartPanel(InventoryToLoad);
                     Debug.Log("No inventory file loaded from: " + Application.persistentDataPath + "/PlayerInventory(" + i + ")Info.dat. Initialize Empty Inventory");
                 }
                 continue;
             }
             else
                 break;
         }
     }
avatar image SkyArchitect · Feb 25, 2016 at 05:12 AM 0
Share
  void StartPanel(Inventory inv)
     {
         GameObject thePanel = Instantiate(Panel) as GameObject;
         thePanel.transform.SetParent(panelholder.transform);
         thePanel.transform.localPosition = new Vector3(0, 0, 0);
 
         //GameObject thePanel = panelholder.transform.GetChild(0).gameObject;
         SlotPanel PaneltoLoad = thePanel.GetComponent<SlotPanel>();
 
 
         PaneltoLoad.inventoryID = inv.inventoryID;
         PaneltoLoad.inventoryName = inv.inventoryName;
         PaneltoLoad.slotAmount = inv.slotAmount;
         PaneltoLoad.gearAmount = inv.gearAmount;
         PaneltoLoad.weaponAmount = inv.weaponAmount;
         PaneltoLoad.potionAmount = inv.potionAmount;
         PaneltoLoad.carryweight = inv.carryweight;
         PaneltoLoad.weight = inv.weight;      
 
         PaneltoLoad.query_amount = inv.query_amount;
         PaneltoLoad.query_dura = inv.query_dura;
         PaneltoLoad.query_equip = inv.query_equip;
         PaneltoLoad.query_id = inv.query_id;
         PaneltoLoad.query_slot = inv.query_slot;
 
         thePanel.name = inv.inventoryName;  
     }
avatar image SkyArchitect SkyArchitect · Feb 25, 2016 at 05:12 AM 0
Share

the way I instantiate the inventory panel (which has the bug)

avatar image SkyArchitect · Feb 25, 2016 at 05:16 AM 0
Share
   public void AddItem(int id, int quantity, int dura)   //pick up item, gain item from NEI or other NPC, also used to reconstruct inventory when reload scene.
     {
         Item itemToAdd = database.FetchItemByID(id);
         Debug.Log(itemlist + " :" + itemlist.Count);        
         for (int i = gearAmount + weaponAmount; i < gearAmount + weaponAmount + slotAmount; i++)
         {
             Debug.Log(itemlist[i].ID);
             if (itemlist[i].ID == id)
             {
avatar image SkyArchitect SkyArchitect · Feb 25, 2016 at 05:17 AM 0
Share

the "itemlist[i]" got an NullReferenceException error

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SkyArchitect · Feb 25, 2016 at 04:57 AM

NullReferenceException: Object reference not set to an instance of an object SlotPanel.AddItem (Int32 id, Int32 quantity, Int32 dura) (at Assets/My Assets/System/Item/Scripts/SlotPanel.cs:514) NEIslot.Use () (at Assets/My Assets/System/Item/Scripts/NEIslot.cs:36) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

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

66 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 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

Script for activating next GameObject after first one has been found/tracked (Vuforia) 1 Answer

OnCollisonEnter2D Not Firing after checking collider 1 Answer

It does not work removing items from the inventory 0 Answers

How can I load/save a Prefab refference? 0 Answers

[SOLVED]Removing gameobject from list don't change the index 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