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 Haversack · Dec 28, 2012 at 04:37 AM · arraynullreferenceexceptionmultidimensional

Can't access Array in a class instance multidimensional Array.

I have a Multidimensional Array

 var cubes: VoxCube[,,];

I set it

 function Awake () {
     cubes = new VoxCube[l,w,h];
 }

I then have a function to fill out all of the data in the VoxCube[,,]

 function BaseChunk() {
     for(var x=0; x < l; x++){
         for(var y=0; y < w; y++){
             for(var z=0; z < h; z++){
                 
                 var isVisible: boolean = false;
                 var isMeshVect: int = 0; // 0 not used 1 used
                 var isGround: boolean = false;
                 
                 if(y == groundOffset){
                     isGround = true;
                     isMeshVect = 1;
                     isVisible = true;
                 }
                 
                 //init location

                 cubes[x,y,z] = new VoxCube();

                 var voxLoc: VoxCube = cubes[x,y,z] as VoxCube;
                 voxLoc.visible = isVisible;
                 voxLoc.origin = Vector3(x,y,z);
                 //setup ghost vertices
 ERROR: null----> voxLoc.ghostVertices[0] = Vector4(x*s,y*s,z*s,isMeshVect); //0,0,0 

VoxCube is this

 class VoxCube extends Object
 {
     public var visible: boolean;
     
     public var origin: Vector3; //point location in VoxLevel
     
     //The basic locations of the 8 Verticies:
     public var ghostVertices: Array;
     
     public var textureIds: Array;//MAX 6 one cube for each side.
     
     public var exportedVertices: Array;
     public var exportedTriangles: Array;
     public var exportedUV: Array;
     
 }

It keeps telling me voxLoc at the first ghostVertices line is a Null Reference Exception. I don't get why voxLoc moments before is fine but as soon as I try to put anything into that array within the VoxCube class it barfs on me. I'm sure it's something simple I'm missing. Any advice is welcome.

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

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

Answer by Eric5h5 · Dec 28, 2012 at 04:53 AM

You need to initialize ghostVertices (and the other arrays) before you can use them. However you really should not use Array, which is slow and not type-safe. Use a built-in array, namely Vector4[], or a generic List of Vector 4, namely List.< Vector4 >, if it's supposed to be a dynamically-sized array. (You still need to initialize them though.)

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 Haversack · Dec 28, 2012 at 03:22 PM 0
Share

Thanks. I should have realized that. Too much time staring at it I suppose :)

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D array in shader 0 Answers

Why is passing this array causing some of its values to become null? 2 Answers

Populating a Vector2 array in Javascript 1 Answer

Multidimensional array of objects in C# 1 Answer

Push Custom Class to Array (JavaScript) 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