Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 stereosound · Sep 29, 2011 at 03:58 AM · javascriptarrays

Referencing data in pre-defined array

So, I a game where it would be ideal to call up characteristics from a pre-defined list, such that if I have GameObject1, I can go to Array[1,2], Array[1,3], etc to pull out its characteristics.

That said, I do not know #1 how to do this (does unityscript have a 2d array function?) and #2 how I can save this information in say, the editor, so I don't have a script in mono that is essentially unnecessary load times seeing as it would never change during runtime. Are there any solutions available in unity for this? Or if not, what is the best work-around?

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 Julien-Lynge · Sep 29, 2011 at 05:17 AM

@stereosound

Unityscript supports regular Javascript arrays (according to this page), so here's how you'd set up the multidimensional array in code.

In order to save the data outside of runtime, you'd have to set up an editor script to collect the data and save it to disk (perhaps in an xml document in Resources) OR set up a custom EditorGUI that would allow you to enter the data as a series of one-dimensional arrays, or other equally exotic solutions.

That being said, if you're really set on manually setting up the array from the editor you probably want to simply flatten the array to be one dimensional (and make sure it's public) and then convert it to a 2d array at runtime (the cpu time to copy an array of pointers at runtime will be absolutely trivial, on the order of nanoseconds).

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 stereosound · Sep 29, 2011 at 05:23 AM 0
Share

Thanks for the quick response! Is loading from an X$$anonymous$$L file a noticeable speed hit? If so, perhaps it is better to just populate the arrays in a public var and merge them at runtime -- thanks for the tip!

avatar image Julien-Lynge · Sep 29, 2011 at 05:45 AM 0
Share

Reading the xml isn't a huge hit, it just requires some extra disk space / memory (see http://forum.unity3d.com/threads/45447-X$$anonymous$$L-Parser-in-C). However it's only really good for saving things like ints or strings - if you're wanting to save references to components or game objects (like it appears you want to do) you pretty much need to set it up with public variables through the editor gui for your script. The overriding reason for this is that you're then linked with the library backend to Unity, so if you change a game object's name or components (for instance) your connection to the object isn't hosed. So the custom EditorGUI would work for you, as would using single-dimensional arrays and merging at runtime.

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

JavaScript 3 Arrays questions 1 Answer

Why can't I push and pop from string array? 1 Answer

What the heck is a 'function(System.Array): void' Type? 2 Answers

Javascript / Unityscript adding elements of an array 2 Answers

My array does not update when object is destroyed. How do I fix it? (java) 2 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