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 /
This question was closed Nov 09, 2016 at 04:38 PM by OussamaB for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by OussamaB · Aug 24, 2013 at 10:58 PM · javascriptarraysizeclasscontent

How to increase the size of a class array?

I've tried using this method to increase the size of my class array by 1 unit:

ClassArray = new ClassVars[ClassArray+1];

But this method clearly removes all the content of the class array and re-creates with the given size which is "ClassArray+1" in this case.

So how do I increase the size of my class array without removing the existing content of the current array?

Thanks in advance, SoumiDelRio

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

  • Sort: 
avatar image
2
Best Answer

Answer by scipiothegreat · Aug 25, 2013 at 12:00 AM

You could use a generic list.

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 OussamaB · Aug 25, 2013 at 12:27 PM 0
Share

I'll be adding/removing content from the array, so I think I'm going to learn how to use generic list. I'll test that when I get home.

avatar image Guppie1337 · Jun 04, 2015 at 05:35 PM 0
Share

This forced me to learn something valuable. Thanks for the simple answer :)

avatar image
1

Answer by Eric5h5 · Aug 25, 2013 at 12:10 AM

You can use System.Array.Resize, but if you're going to be adding/removing from the array, you'd be better off with a generic List in most cases.

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 DaveA · Aug 24, 2013 at 10:59 PM

It's all here: http://docs.unity3d.com/Documentation/ScriptReference/Array.html

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 · Aug 25, 2013 at 12:05 AM 0
Share

No, that's about the JS Array class (which should never be used), not built-in arrays, which the question is asking about.

avatar image OussamaB · Aug 25, 2013 at 12:26 PM 0
Share

I already tried that before posting my question, does not work.

avatar image
0

Answer by trs9556 · Aug 24, 2013 at 11:24 PM

If there isn't a specific method to do that you could make a new array that is the same size as your current array, then store all of your values in that new temp array, increase your array by however much you want (not having to worry about the values because they are being held in another array) then assign the values to that new sized array.

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 DaveA · Aug 24, 2013 at 11:44 PM 0
Share

You have to learn how to use 'answer'

avatar image DaveA · Aug 24, 2013 at 11:45 PM 0
Share

And the page I linked to has code to do what you say. It's called the Scripting Reference and it's essential to read it.

avatar image Eric5h5 · Aug 25, 2013 at 12:06 AM 0
Share

It's also essential to know not to use the Array class. Just pretend it doesn't exist (same for ArrayList). http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Creating a dynamic array of objects of custom class 1 Answer

Reading and Storing External Data into Memory (From Text) 1 Answer

Different way to access class variables? 1 Answer

Static array with custom class? 1 Answer

Creating A Class Variable That Works With Any Class 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