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 dakenho · Oct 31, 2014 at 11:18 PM · listlistsmultidimensional array

multi dimensional array of lists

I am trying to create a multidimensional array of lists that stores what is on a specific tile on my grid basically the end goal is to get here item = map_data.mapdata[x, y][i]; from what i can gather from other forms posts it should look like this

 public class mapdata
 {
 
     public List<int>[,] map_Data;
     public mapdata(int sizex, int sizey)
     {
         map_Data = new List<int>[sizex, sizey]; 
     }
 }
 
 public mapdata map_data = new mapdata(size_x,size_y);
 
 public DTileMap(int size_x, int size_y)
 
 {
 
         for(int x=0;x<size_x;x++) {
 
             for(int y=0;y<size_y;y++) {
 
                 map_data.map_Data[x,y].Add(3);
 
 
             }
 
         }
 
 
 }

but it tells me that

NullReferenceException: Object reference not set to an instance of an object DTileMap..ctor (Int32 size_x, Int32 size_y) (at Assets/TileMap_D/DTileMap.cs:107)

Comment
Add comment · Show 1
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 Kiwasi · Nov 01, 2014 at 07:43 AM 1
Share

Fixed your formatting for you. Its the button up the top with 101010 on it.

The problem as others have indicated it the lack of initialisation. But this data structure looks messy. You should think carefully if this is actually the way you wish to represent your data.

1 Reply

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

Answer by zharik86 · Nov 01, 2014 at 07:15 AM

I'm not sure, that it's rigth declare:

  public List<int>[,] map_Data;

But if works, than you create multi list, but not initialization it. Try:

  public mapdata(int sizex, int sizey) {
   map_Data = new List<int>[sizex, sizey];
   //Initialization each list
   for(int i = 0; i < sizex; i++) {
    for(int j = 0; j < sizey; j++) {
     map_Data[i, j] = new List<int>();
    }
   }
  }

I hope that it will help you.

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

27 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

Related Questions

A node in a childnode? 1 Answer

Creating a multidimensional array List 2 Answers

Respawning gameobject not working c# 0 Answers

Copy values between two classes in two lists. 1 Answer

Make Lists within a List 0 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