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 /
This question was closed Jul 22, 2011 at 09:59 PM by Chris D for the following reason:

Null reference solved, other issue resolved by user.

avatar image
0
Question by Blankzz · Jul 22, 2011 at 03:27 PM · nullreferenceexceptionscriptableobject

NullReference exception problem

Hi

I have the following code which produced the error "NullReferenceException: Object reference not set to an instance of an object" at the line where I try to enqueue one of the linkedDialogues but I'm not sure why I am getting the error because if I log the object I seem to be able to access it. The Dialogues extend ScriptableObject. I'm not sure if this is the problem. Any ideas anyone?

 float currentPosX = 20.0f;
         Queue<Dialogue> queue = new Queue<Dialogue>();
         queue.Enqueue(workingSequence.RootDialogue);
 
         while(queue.Count > 0)
         {
             Dialogue currentDialogue = queue.Dequeue();
             if(currentDialogue == null)
             {
                 Debug.Log("null");
                 continue;
             }
 
             for (int index = 0; index < currentDialogue.linkedDialogues.Count; index++ )
             {
                 if (currentDialogue.linkedDialogues[index] != null)
                 {
                     Debug.Log(currentDialogue.linkedDialogues[index].name);
                    //ERROR IN THIS LINE BUT CAN ACCESS OBJECT WITH ABOVE LOG STATEMENT 
                    queue.Enqueue(currentDialogue.linkedDialogues[index]);
                 }
             }
 
             nodes.Add(new DialogueNode(currentDialogue, this, nodes.Count + 1, new Rect(currentPosX, 20, 400, 0)));
             currentPosX += 200.0f;
         }
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

  • Sort: 
avatar image
0

Answer by Chris D · Jul 22, 2011 at 04:40 PM

Won't

 for(int index = 0; index < currentDialogue.linkedDialogues.Count; index++ )

go beyond your index by one (because of 0-indexing)?

 for(int index = 0; index < currentDialogue.linkedDialogues.Count-1; index++ )

instead.

Comment
Add comment · Show 1 · 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 Blankzz · Jul 22, 2011 at 09:42 PM 1
Share

Although that wasn't the route of my problem because I was getting an exception with all references, your right that did cause an exception but an out of range exception. It turned out the I was doing something random in the lists getter function so I've solved the issue now thanks.

Edit: Sorry about posting as an answer I was responding through my mobile and got confused. Anyway I was going to tick your answer but as my title is asking about the null reference exception and your answer was about the loop possibly going out of range I thought it would be best not to tick it to save confusion. Its probably a better idea to close the question to answers as I solved the original question myself but I don't have the power to do so.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Scriptable Object is getting set to null 0 Answers

NullReference on trying to instantiate a prefab which has been set using scriptable object,Particle giving null reference but works in scene view 0 Answers

ScriptableObject assets null on startup, then reappear? 1 Answer

Why does ScriptableObject.CreateInstance, where T is definite at runtime, return null? 1 Answer

Editor Window/Scriptable object - null problem 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