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?
to see 2d arrays in the inspector try this:
var array2d : MyArray[];
class MyArray{
var myArray : float[];
}
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: Unity3D - 2D Array In Inspector - YouTube
Its in c# though.
Simple example, allows editing in Inspector non-debug mode:
[System.Serializable]
public struct NPCImgs
{
[SerializeField] public Sprite[] Img;
}
public NPCImgs[] CharSprites;
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.
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:
Hello there,
I just came across this question today at work and solved it,
I made a GitHub for this: GitHub - Eldoir/Array2DEditor: Use 2-dimensional arrays in Unity's Inspector.
Hope you’ll like it
If you want a matrix for Coordinates you can do it also like this :
public Vector2[] vectorName;
In inspector you can set the vector size and also can set x and y for each element inside vector;