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 jtbentley · Sep 23, 2010 at 05:21 AM · gameobjectinstantiateiphonefind

Finding children of an instantiated object

I'm spawning a vehicle, and wish to link the left and right tyres that get spawned as part of the prefab's array.

playerCarBody = Instantiate (carPrefabs[0], playerCarSpawn.position, playerCarSpawn.rotation); playerCarAudio = playerCarBody.audio;

// Here's the tricky bit frontPlayerTyres[0] = gameObject.Find("Wheel_Left").transform; frontPlayerTyres[1] = gameObject.Find("Wheel_Right").transform;

Specifically, I want to be able to search only in the child of that instantiated car, so in essence I want to do a Find(playerCarBody.Find("Wheel_Left") sort of thing.. I'm not quite sure of the syntax on how to do that one :)

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
4
Best Answer

Answer by · Sep 23, 2010 at 05:25 AM

I think you're looking for Transform.Find

function Find (name : string) : Transform

Finds a child by name and returns it.

Updated

Note that you can do the same with GameObject.Find, if you pass in a specific search path.

// This will return the game object named Hand, which is a child of Arm -> Monster.

// Monster may not have a parent in the hierarchy view!

hand = GameObject.Find("/Monster/Arm/Hand");

So for your example, you'd want:

frontPlayerTyres[0] = gameObject.Find("/playerCar/Wheel_Left").transform;
// where 'playerCar' is the name of the object instantiated from the playerCarBody prefab.
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 jtbentley · Sep 23, 2010 at 05:38 AM 0
Share

Nearly, but it sent me on the right path.. Because there are several vehicles with identical names, that didn't quite work.

What did work was frontPlayerTyres[0] = playerCarBody.transform.Find("Wheel_Left") :)

avatar image · Sep 23, 2010 at 05:57 AM 0
Share

Ah, good to hear it. I upvoted the question as I'm sure it's something that others will want to know.

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

No one has followed this question yet.

Related Questions

How to spawn a GameObject by name? 2 Answers

All subsequent instantiated objects = auto-named with suffix (Clone)? 1 Answer

Limiting respawns on scene 1 Answer

How do I instantiate same tag/name GameObjects with an array 1 Answer

Detect when instance has deleted 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