Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Quakeulf · Dec 22, 2016 at 02:39 PM · gameobjectruntimefindgameobjectswithtaggameobject.findfindwithtag

What's the most efficient way of finding child objects at runtime?

I have a prefab that will be added to X amount of objects, and these prefabs have Y amount of child objects. These child objects have a few objects under them too.

What I would like to is to be able to access them locally per gameobject I instantiate them at like this:

Prefabname.Childname.ChildsChildname.TheObject.setActive(true);

Is this possible? It would save me a lot of time.

Thank you very much for helping out.

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 jmgek · Dec 22, 2016 at 05:24 PM

While you can search through transforms in order to find their children I would suggest creating a list of children on the parent object that would store the children.

This is faster than searching the entire scene for a game object by name or tag. And in most cases the best way to refence objects.

How are you creating the children? Are you actually instanceing or are you just setting them active?

Either way on instance or start you can use:

 //parent list holder. Cs
 List<gameovject> children... 
 
 //child 
 This. Game object. Transform. Parent. Getcomponent<listholder>().children.add(this.gameobject)

Sorry on my phone, this adds to a parents list of children by using the child object to populate it. Use can use this recursively to search any amount of children as long as they have a list and that code.

Does that make sense? Is this what your looking for?

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 Quakeulf · Dec 22, 2016 at 08:04 PM 0
Share

Hi, The Prefab has all the childobjects on it already. The only thing instantiated is the Prefab itself.

Using a list is what we decided to try as well, but I will get to test this tomorrow, so yes, this is something I looked for.

avatar image jmgek Quakeulf · Dec 22, 2016 at 08:32 PM 0
Share

No worries, yes that logic will work if you put it in the class 'start or constructor' on any game object. It's basically registering itself to a parent.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't figure out how to access an object after creation.,Can't figure out how to access a given instance of the object on mouse click. 1 Answer

Need help finding the closet player to an enemy 2 Answers

Find one inactive player (gameobject) 2 Answers

Toggling a game object between an active and inactive state 1 Answer

How to access a game object from a different scene? 0 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