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 benfattino · Sep 24, 2012 at 07:45 PM · arraychildren

array of childern

There is a way to do an array of object like to using Component.GetComponentsInChildren command?

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 Brian Stone · Sep 24, 2012 at 08:15 PM 0
Share

I'm afraid that your question doesn't make a lot of sense. Nothing is preventing you from creating an array and filling it with anything you want. If you're not sure how to code arrays in Javascript (and Javascript-like languages, such as Unityscript), then please read the W3Schools documentation...

http://www.w3schools.com/js/js_obj_array.asp

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Sep 24, 2012 at 09:43 PM

I think you are probably after an array of GameObjects which are the children of the current object?

If so then you have two choices - all of the children or the immediate children. Unforunately you didn't say what language you wanted it in...

C#

 using System.Collections.Generic;
 using System.Linq;
 
 //Immediate children
 
 var myChildren = transform.Cast<Transform>().Select(t=>t.gameObject).ToArray();
 
 //All children, not including self
 
 var allChildren = GetComponentsInChildren<Transform>().Except(new [] { transform }).Select(t=>t.gameObject).ToArray();

JS

 import System.Linq;
 ...
 var myChildren = transform.Cast.<Transform>().Select(function(t) { return t.gameObject; }).ToArray();
 
 //All children not self 
 
 var allChildren = GetComponentsInChildren(Transform).Except([transform]).Select(function(t) { return t.gameObject;}).ToArray();
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 benfattino · Sep 24, 2012 at 10:04 PM 0
Share

I apologize. I explained bad anyway you know. I'm not familiar with C. .. if you could have a JavaScript version would be better, otherwise does the same. Somehow I manage very well. Thanks for answer.

avatar image whydoidoit · Sep 24, 2012 at 10:09 PM 0
Share

I always get the wrong language first and without the ability to compile right now am not totally convinced about that [transform] in the all children line... Let me know if it works.

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

11 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

Related Questions

List children with name in array? 3 Answers

Take array and waypoints from parent spawnner 2 Answers

How to load all vertices form multiple children of a game object in to one big array? 0 Answers

Find Child of GameObject from Array in Different Script 0 Answers

Filling an array with child vectors 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