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
2
Question by OmegaVemon · Nov 25, 2010 at 03:04 AM · arraysserialization

Array of arrays = No serialization?

The docs say Unity doesn't support serialization of an array of arrays... So I can't save such data?

How about... a Hashtable of hashtables?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
13

Answer by thorbrian · Dec 01, 2011 at 06:30 PM

Just do an array of objects with an array in them, and Unity will serialize that and be able to show it in the editor just fine:

public class ThingWithArraysOfArrays : ScriptableObject 
{
    [System.Serializable]
    public class ThingWithArrays
    {
        public int[] array;
    }
    public ThingWithArrays[] array;
}

that will solve your serialization problem at the cost of accessing the nested array like: container.array[x].array[y] instead of container.array[x][y], but if that's a problem, you could try adding an overload of the [] operator to the ThingWithArrays like this:

public int this[int i]
{
    get
    {
        return array[i];
    }
    set
    {
        array[i] = value;
    }
}

... and if you are using javascript instead of C#, well sorry.

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
0

Answer by Jesse Anders · Nov 25, 2010 at 12:32 PM

Usually there are ways to get around the limitations of Unity's serialization system. One option in your case might be to create a serializable custom class that has an array as a member, and then create an array whose element type is that class (I think this would work, but I'd have to try it to be sure). If you're just wanting a (square) 2-d array, another option would be to store the data as a 1-d array and provide accessors that support 2-d indexing.

Comment
Add comment · Show 2 · 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 OmegaVemon · Nov 27, 2010 at 12:31 AM 0
Share

So having an array linking to GameObjects that are storing another array will work just fine?

avatar image Jesse Anders · Nov 27, 2010 at 01:20 AM 0
Share

I'm not quite sure what you mean, but regardless, an effective way to find out would be just to try it :)

avatar image
0

Answer by Ben 20 · Feb 10, 2011 at 04:28 PM

If you want a 2D array, then you should be able to implement this into your project.

Comment
Add comment · Show 2 · 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 Eric5h5 · Feb 10, 2011 at 04:34 PM 0
Share

That's obsolete now in Unity 3.2.

avatar image PrimeDerektive · Feb 10, 2011 at 05:14 PM 0
Share

Straight from the horse's mouth! :)

avatar image
0

Answer by legopatch · Dec 01, 2011 at 05:10 PM

I used a hashtable of hashtables to save the objects in my project, using the propertylist serializer on the wiki.

for it to work though I had to have an array that stored the name of each sub hash table, that way I would know what to iterate through.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Cannot convert object[] to Vector3[] 2 Answers

Serializating a base class array to a prefab 2 Answers

When attempting to serialize and save a jagged array it gives me an error message 1 Answer

Serializing class that has List of members of same type and referencing them in scene causes awfull long assembly reload time 0 Answers

Initialization of Classes Instantiated in an Array in the Inspector 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