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
1
Question by montblack · Aug 03, 2010 at 07:08 AM · addbuiltin array

problem adding an item to a builtin array

I have a problem when I try to do something like this

var enemies = new myClassName[0];

in the inspector works great, but if i want to add a new object to the builtin array directly from my .js code how i can do that? i tried this:

var enemies = new myClassName[0];

enemies.Push(new myClassName()); -> error enemies.Add(new myClassName()); -> error enemies= new myClassName(); -> error enemies[i] = new myClassName() -> i is the last index + 1 (error) enemies.Resize=N; -> error : 'self.punto.Resize' has not been correctly processed.

(and sorry for my english i speak spanish)

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
2
Best Answer

Answer by StephanK · Aug 03, 2010 at 09:32 AM

//this shows up in inspector var builtinArray : MyClass[];

function Start () { // this creates a js array with the contents of builtinArray var enemies = new Array(builtinArray); enemies.push(new MyClass()); }

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 montblack · Aug 03, 2010 at 04:54 PM 0
Share

thanks, but this way will not appear in the inspector. if I declare as Array () and not as $$anonymous$$yClassName [], I can not configure the features of my objects from the inspector, I need a form that allows me to create objects from the inspector and from. JS

avatar image StephanK · Aug 04, 2010 at 10:01 AM 0
Share

Personally I don't use JS, but here http://unity3d.com/support/documentation/ScriptReference/Array.html it says that JavaScript arrays don't show up in the inspector. Builtin arrays however show up in the inspector, but can't be resized, so push and add won't work. But you CAN convert a builtin array into a JS array to get the best of both worlds.

avatar image montblack · Aug 05, 2010 at 05:15 PM 0
Share

great solution thank speree

avatar image StephanK · Aug 06, 2010 at 10:00 AM 0
Share

I stole it from the documentation. You should read it sometime... ;)

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

No one has followed this question yet.

Related Questions

Terrain collider - add 2 Answers

Create a game objective. 0 Answers

Add GameObjects to an Array List on RayCastHit 1 Answer

Filling up an array with GameObjects 0 Answers

I Dont Get How I Use List.Find 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