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 /
This question was closed Jul 18, 2016 at 06:06 PM by hfpngaming for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by hfpngaming · Jul 16, 2016 at 10:59 PM · null reference exceptionnull reference

NullReferenceException making no sense

I have already tried a lot of debugging on this and it make no sense whatsoever. I made sure that the problem exists in the following code block, when i try to access any of the items in the array it gives me an error. I have also made sure that the array is initialized before i access it. I feel like its something stupid and for some reason i can't see it.

     public void SetVertDataLength()
     {
         if (setVertData)
         { 
             vertData = new VertexData[pipeSegmentCount * maxCurveSegCount];
             for (int i = 0; i < vertData.Length; i++)
             {
                 vertData[i] = new VertexData();
             }
             setVertData = false;
         }    
     }

this is where i try to access the array and again i've already check that this code runs after the previous

     private void CreateQuadRing(float u, int i)
     {
         float vStep = (2f * Mathf.PI) / pipeSegmentCount;
         int ringOffset = pipeSegmentCount * 6;
         VertexData vertex = new VertexData();
         vertex.originalU = u;
         vertex.originalV = 0f;
         vertex.RandomizePosition();
 
         for (int v = 1; v <= pipeSegmentCount; v++, i += 6)
         {
             // the following line is where the error occurs
             vertData[i].CopyVertexData(vertData[i - ringOffset + 4]);
 
             vertData[i + 1].CopyVertexData(vertData[i - ringOffset + 5]);
             vertData[i + 2].CopyVertexData(vertData[i - ringOffset + 5]);
 
             vertData[i + 3].CopyVertexData(vertex);
             vertData[i + 4].CopyVertexData(vertex);
 
             vertData[i + 5].originalU = u;
             vertData[i + 5].originalV = v * vStep;
             vertData[i + 5].RandomizePosition();
             vertex = vertData[i + 5];
 
         }
     }
Comment
Add comment · Show 4
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 Le-Pampelmuse · Jul 17, 2016 at 12:54 AM 1
Share

What have you tried to solve it?

The problem seems to lie in your VertexData type. Where does it come from? Did you implement it yourself?

Trying your code with working types like a vector3:

 void Start()
 {
     vertData = new Vector3[3 * 4];
     for (int i = 0; i < vertData.Length-1; i++)
     {
     vertData[i] = Vector3.zero;
     }
 }

I was substituting your length variables pipeSegmentCount and maxCurveSegCount with 3 and 4 because it doesn't matter for evaluation of the code.

That code will create a Vector3 array "vertData" at Start with 12 Vector3's (0,0,0) in them: alt text

$$anonymous$$y guess is that at the moment where the line with the error is executed the referred index of

 vertData[i - ringOffset + 4]

has not been initialized, or has been set to null for whatever reason.

Just a thought: I'm quite sure that the compiler would tell you if it was exceeding the array size, it would always tell you that via the "index out of range" error.

Try to print the name of the element in the array that you want to work with above that line:

 print(vertData[i - ringOffset + 4]; // .name or whatever value you can access from that type.
 vertData[i].CopyVertexData(vertData[i - ringOffset + 4]);

This will give you closure if that object is null or not.

Hope I could help somehow. It's difficult without knowing the datatypes in custom scripts.

array.png (16.8 kB)
avatar image hfpngaming Le-Pampelmuse · Jul 18, 2016 at 06:05 PM 0
Share

Thanks for your reply, it turns out that the array was initialized twice and that ended up causing the issue. Thanks for the help tho, much appreciated.

avatar image ItTookMe2MonthsToCreateAnAccountHereSuccessfully hfpngaming · Jul 21, 2016 at 06:58 PM 0
Share

If someone helps you, give them a upvote ;)

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

49 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

Related Questions

"NullReferenceException: Object reference not set to an instance of an object GameHelper.Update () (at Assets/Scripts/GameHelper.cs:44)" 2 Answers

#Need Fast Help# NullReferenceException: Object reference not set to an instance of an object 0 Answers

null reference help. i fundamentally dont understand. 1 Answer

null reference on instantiated prefab array at instantiation 1 Answer

NullReferenceException: Object reference not set to an instance of an 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