Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 iamthecoolguy11 · Oct 28, 2013 at 06:27 AM · objectchildifcount

how do i tell how many childs a object has

Im making a script that loops threw childs of a object and i need the script to know how many childs it has so that it know when to go back to 0.

here's a demonstration

 var holder : GameObject;
 var number : int = 1;
 
 function Update()
 {
   if(somthing Happens)
   {
    number += 1;
 //some how make this "if" know when "holder" runs out of childs
 if()
    {
      number = 0;
    }
   }
 } 

thanks in advance :] and thumb up this question plz

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 Griffo · Oct 28, 2013 at 06:41 AM 1
Share

Here

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by hirenkacha · Oct 28, 2013 at 07:03 AM

  1. Declare an array containing the children : Transform[] children.

  2. Populate the array as follow: children = gameObject.GetComponentsInChildren<Transform>();

  3. You can now check the length of the array using children.Length to get the total number of children

Comment
Add comment · Show 1 · 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 Firedan1176 · Oct 25, 2021 at 08:14 PM 0
Share

This will work, however note that this may be more computationally intensive than simply calling transform.childCount. Since the question doesn't mention modifying the objects and just getting the count, you do not necessarily need references to the objects just to get the count.

avatar image
4

Answer by guinoalaskapp · Jun 13, 2021 at 06:40 PM

Also Transform.childCount works too

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 SquashedGames-Studios · Jun 14, 2021 at 01:15 AM 0
Share

Yeah, why is the over-complicated solution marked as correct?

avatar image Soda_M7 · Oct 25, 2021 at 07:50 PM 0
Share

That's much easier, but it is with transform.childCount, without the T capitalized.

avatar image
0

Answer by Griffo · Oct 28, 2013 at 06:48 AM

I think this will point you in the right direction Here

Comment
Add comment · Show 1 · 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 iamthecoolguy11 · Oct 28, 2013 at 06:54 AM 0
Share

can you explain in your own words

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

21 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

Related Questions

rapid movement back and forth 1 Answer

Help for shots in a script 2 Answers

How to access objects attached to other objects 1 Answer

How do I access/use the variable inside a script when the script name is unknown but objectname is? 3 Answers

Counting active objects in a list 3 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