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
7
Question by matty348 · Mar 25, 2012 at 03:32 AM · arrays2d arraymultidimensional array

Is there any way to view 2d arrays in the inspector?

I am scripting in javascript and don't seem to be able to view the 2d arrays that I create in the inspector. Is there a way around to fix this?

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 syclamoth · Mar 25, 2012 at 03:34 AM 0
Share

Look up multidimensional arrays on this site. It's a known problem, and there exist many workable solutions.

7 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by Wilaxxx · Mar 25, 2014 at 03:33 PM

to see 2d arrays in the inspector try this:

  var array2d : MyArray[];
 
 class MyArray{
      var myArray : float[];
  }
Comment
Add comment · Show 8 · 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 gitoffame · Jul 08, 2014 at 11:03 PM 0
Share

Thank you, Wilaxxx. This will come in very handy.

avatar image OP_toss · Jul 08, 2014 at 11:22 PM 1
Share

$$anonymous$$eep in $$anonymous$$d, if you make a tree structure using this, Unity will only serialize 7 levels deep before just giving up. So this works for simple 2 depth matrices or something, but deep trees won't work.

avatar image Atabek · Oct 24, 2014 at 08:31 PM 0
Share

Thank you, Wilaxxx. In JS all work great but when i try it in C# it won't show in inspector :( Any suggestion how to fix this, or it impossible?

avatar image Atabek · Oct 24, 2014 at 08:39 PM 7
Share

Hehe just found it by my self. Here is c# example all You need to do is add [System.Serializable] before class declaration.

 [System.Serializable]
  public class $$anonymous$$ultiDimensionalInt
  {
  public int[] intArray;
  }

Then you can build an array of it in your main class like this:

 public $$anonymous$$ultiDimensionalInt[] myIntArray;

avatar image kalibcrone Atabek · May 22, 2019 at 01:35 AM 1
Share

Something important missing from this example is how to access the multiple dimensions. Here is an example of how to do so

 myIntArray[row].intArray[column]
avatar image WaqasHaiderDev kalibcrone · May 28, 2020 at 11:22 PM 0
Share

Thanks a lot @kalibcrone . I made class last day and I was struggling a lot to access members. I was just going to reject this approach and then I cam across your answer. You said right, this missing part is really important and I really thank you for this.

Regards,

avatar image developer_arni · Nov 12, 2014 at 09:18 PM 1
Share

And the source of Atabeks answer: http://answers.unity3d.com/questions/53038/visializing-a-multidimensional-array.html

Show more comments
avatar image
5

Answer by sumeetkhobare · Jul 13, 2015 at 10:37 AM

Hey,

I stumbled in this same issue a month ago and after solving it, I have made a solution to this, now. I have made a grid view for a 2D array.

You can find it here: https://youtu.be/uoHc-Lz9Lsc

Its in c# though.

Comment
Add comment · Show 3 · 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 danielcestrella · Jan 11, 2016 at 11:03 AM 0
Share

Thank you! A lot of time looking for something like that!

avatar image guneyozsan · Sep 05, 2016 at 02:38 PM 0
Share

I wish you put the answer here as well. It will be more reliable for future as links may become broken over time. By the way, thanks for the solution.

avatar image z_orochii · Jul 23, 2017 at 09:49 PM 1
Share

Thanks for the video. I actually gave it a shot and found this thing, dunno if you already saw it, but I was able to make my 3D array visualization by following your video and using the SerializedProperty.getArraySize property to be able to use whatever size the original array has.

i.e.

 SerializedProperty data = property.FindPropertyRelative("rows");
 for (int x = 0; x < data.arraySize; x++) {
   // do stuff for each member in the array
   EditorGUI.PropertyField(newPosition, data.GetArrayElementAtIndex(x), GUIContent.none);
 }

Hope it helps somebody.

avatar image
2

Answer by Bunny83 · Mar 25, 2012 at 03:37 AM

No, multidimansional arrays are not serialized by Unity and therefore can't viewed in the inspector.

edit
The only way is to use an array of a serializable class / struct which contains another array. See this question for more details. I know there are a lot better examples around, but can't find them at the moment.

Comment
Add comment · Show 4 · 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 Berenger · Mar 25, 2012 at 04:25 AM 0
Share

Or you always can use a custom inspector. I find it annoying most of the time but if it helps ...

avatar image Bunny83 · Mar 25, 2012 at 10:42 AM 0
Share

@Berenger: Sure, but it won't serialize the array, so what's the point of showing it in the editor ;) Just to view the data?

avatar image Zarenityx · Feb 06, 2013 at 08:27 PM 0
Share

exactly. So you can see if it works without using print messages, which I fing extremely cumbersome when using containers with more than 1 dimension. Also, you could edit it.

avatar image Bunny83 · Feb 06, 2013 at 09:30 PM 0
Share

For this purpose i've developed my "own" ingame inspector which is part of my debug class. It can list all objects variables (public and private). $$anonymous$$y class also supports DrawLine and even DrawQuad at runtime. I also integrated a console window for Debug.Log messages. At the moment it's not in a state i can publish it. $$anonymous$$aybe if i can find the time to polish it i'll release it ;)

It's build very modular so you can add very easy your own modules (actually almost like the UnityEditor, but at runtime ;)). I've made this mainly for debugging support on mobile platforms. The GUI is of course optimised for touch input ;)

Well, i think i shouldn't talk too much about it, maybe it will never be done...

avatar image
2

Answer by Goshand · Sep 19, 2015 at 08:54 PM

Hey guys,

If you want to use a 2d List of something like tiles for a Tile map, I wrote a fun solution that makes a wrapper around a 1d List and allows you to work with them as if they it were a 2d List with a minor change in notation for accessing elements.

Using my class, you can create a 2d map of tiles like this:

public Map map = new Map();

Add lists of tiles (rows) to the map like this:

map.Add(row);

Then get and set elements on the map like this:

Tile aTile = map[1,0];

map[2,3] = aTile;

Here's the Map class:

alt text


screen-shot-2015-09-19-at-20606-pm.png (166.2 kB)
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
avatar image
2

Answer by Sarchy · Nov 28, 2016 at 02:33 PM

Simple example, allows editing in Inspector non-debug mode:

 [System.Serializable]
 public struct NPCImgs
 {
     [SerializeField] public Sprite[] Img;
 }

 public NPCImgs[] CharSprites;
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
  • 1
  • 2
  • ›

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

17 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

Related Questions

Implementing a 2D array as a field on a ScriptableObject? 1 Answer

How to make custom 2 dimensional enum array class 1 Answer

How to remove null's from 2d array ? It's removing but only 2 out of 4 null's. 0 Answers

Javascript 2D arrays: null values and slicing 1 Answer

Array Within 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