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 lentulus · Jul 07, 2013 at 10:25 PM · arrays

Getting the size of an array of GameObjects

I hope this isn't a dumb question - but I am having trouble getting the length of an array of gameobjects using c#. The array is populated in the inspector. But for some reason objects.Length, objects.Size, and objects.Count do not work.

Thank you for any help!

public GameObject[] objects;

Comment
Add comment · Show 1
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 Oribow · Jul 07, 2013 at 11:55 PM 0
Share

can you give us the complet code (all text in the script)?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Loius · Jul 07, 2013 at 10:32 PM

Do not work in what way? Because objects.Length is the way to do it.

If there are any errors they are likely interfering with expected results.

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 dhruv777 · Aug 16, 2017 at 02:09 PM -1
Share

thanks. But how do we increment this object.length .

avatar image Bunny83 dhruv777 · Aug 16, 2017 at 06:47 PM 0
Share

The size \ length of an array can't be changed. Once created the size of an array will be constant.

If you need to change it you have to create a new array and copy the old elements over. You can use System.Array.Resize which does that for you.

However when you frequently need to add \ remove elements you might want to use a generic List ins$$anonymous$$d.

Next time when you have a question you should ask a question and not necropost such an old question with a comment

avatar image
3

Answer by aldonaletto · Jul 07, 2013 at 11:23 PM

Length is a property, not a method, thus there are no parenthesis. In C# it's capitalized:

 int howMany = objects.Length;

In JS it's low case:

 var howMany = objects.length;

EDITED: JS actually accepts both, lowercase and uppercase (see the comments in this answer and in the others).

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 Eric5h5 · Jul 07, 2013 at 11:29 PM 2
Share

It's uppercase in JS. .NET is .NET regardless of language. You may be able to use lowercase as an alternative (I haven't tested it), but if so that's an aberration and should be avoided for the sake of consistency, since properties in .NET are always uppercase. (Sadly properties in the Unity API are not.)

avatar image aldonaletto · Jul 07, 2013 at 11:41 PM 0
Share

Yes, I've just tested this: JS accepts both, uppercase and lowercase.

avatar image Eric5h5 · Jul 07, 2013 at 11:50 PM 1
Share

Well, just pretend lowercase doesn't work. ;)

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

22 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 avatar image avatar image avatar image

Related Questions

transform array in javascript 2 Answers

problem accesing arrays 2 Answers

Multidimensional GameObject Arrays 1 Answer

Create a Word Game like Scrabble in Unity? 0 Answers

Creating an inventory/weapon array and ability to scroll through it 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