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
0
Question by Jeffo · Sep 18, 2013 at 08:01 PM · gameobjecttransformarraylength

C# Variables Transform vs GameObject

Hi all,

I'm currently working through a tutorial (http://vimeo.com/album/1546437/video/20685520) and am a bit confused about Transform variables vs GameObjects.

I've encountered them in the past and they seem pretty similar, but in this particular tutorial (while doing it in C#) I came across an issue trying to use GameObjects[] as an array and trying to grab the length, whereas it worked fine as Transforms.

If someone could clarify the differences for me, that would be fantastic. I am aware of the analogy of the GameObject being the container and the Transform is a component, I'm just confused why making an array of GameObjects isn't behaving like an array.

     Transform[] transArray = Selection.transforms;
     GameObject[] goArray = Selection.gameObjects;
     
     int transLength = transArray.Length;
     int goLength = goArray.length; // Doesn't recognize this property


Thanks much!

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
0

Answer by meat5000 · Sep 18, 2013 at 08:02 PM

int goLength = goArray.length

Needs ; on the end.

Also the line above you have capital L not lowercase, which works. Copy that.

So

  int goLength = goArray.Length;
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 Jeffo · Sep 18, 2013 at 08:24 PM 0
Share

Sorry - I was being lazy. That makes no difference for some reason. When typing the .length, it doesnt even recognize it as a property on the goArray.

avatar image Jeffo · Sep 18, 2013 at 08:31 PM 0
Share

I was doing the lower case and ; to illustrate it wasn't grabbing it as an actually property of that variable.

avatar image meat5000 ♦ · Sep 18, 2013 at 08:39 PM 0
Share

Have you populated your array?

avatar image meat5000 ♦ · Sep 18, 2013 at 08:44 PM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Selection-gameObjects.html

It doesnt say why but this page says it is strongly recommended to use transform version of function. I think you have stumbled upon one of those weird Unity mysteries.

Also it seems that Selection is only for use within the editor, not sure if you are aware of that.

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

16 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

Related Questions

Array.length edited using scripts 2 Answers

Getting the transform from a GameObject list 3 Answers

Keep adding targets to a list 2 Answers

How do I check multiple gameObjects transform positions? 3 Answers

Instantiating from an object that's in an array 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