Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
11
Question by nishants · May 28, 2013 at 12:31 PM · instantiatechild

access child of a gameobject

I am using instantiate() to clone a gameobject and have stored the cloned gameobject in a variable named rocketInstance.This new gameObject have three children named marker,starter and plane. I want to store the marker gameObject in a variable named trrigerObject. I have tried the following trrigerObject=rocketInstance.marker; trrigerObject=rocketInstance.GetComponent("marker");`

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 misiekkox · Feb 20, 2015 at 11:07 AM 0
Share

Hi, if I have a gameObject 'rat' attached to a $$anonymous$$ainCamera i should; GameObject rat;

void Start(){ rat = ParentGameObject.transform.GetChild (0).gameObject; } ???

7 Replies

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

Answer by clunk47 · May 28, 2013 at 05:43 PM

Try Transform.Find or GetComponentInChildren

Comment
Add comment · 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
30

Answer by chetanisinanand · Jul 23, 2014 at 06:29 PM

Easiest way would be : Get Child transform using its index , and then get GameObject of that child transform:

 GameObject  ChildGameObject1 = ParentGameObject.transform.GetChild (0).gameObject;
 GameObject  ChildGameObject2 = ParentGameObject.transform.GetChild (1).gameObject;

And so on .....

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 BonusB · Jul 03, 2020 at 10:59 AM 0
Share

Thank u senpai !!!!!!

avatar image
2

Answer by SuryaPrakashModi · Jul 09, 2018 at 09:27 AM

https://youtu.be/OffZiiq0qcI

Comment
Add comment · 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
1

Answer by Imankit · May 28, 2013 at 01:15 PM

just use this.trrigerObject must be GameObject variable

 trrigerObject=rocketInstance.GetChild("marker");
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 nishants · May 28, 2013 at 01:42 PM 0
Share

Got this error, "$$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'UnityEngine.Rigidbody.GetChild'." I am using trrigerObject as a RigidBody variable.

avatar image Flailer · Apr 02, 2014 at 09:05 AM 0
Share

Yes because GetChild does not exist as a method of gameObject....

avatar image
0

Answer by SubatomicHero · May 28, 2013 at 01:08 PM

I would attach a script to your marker gameobject like so:

 // C#
 
 public GameObject myMarker;
 
 void Start()
 {
     marker = this.gameObject;
 }
 
 // JS
 
 var myMarker : GameObject;
 
 function Start()
 {
     marker = this.gameObject;
 }

Making it public means other scripts can now access this gameobject.

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 nishants · May 28, 2013 at 01:21 PM 0
Share

it didnt solved my problem. I am still using

 trrigerObject=rocketInstance.marker;

to store marker gameObject into triggerObject variable,but inspector panel still shows triggerObject as empty.

  • 1
  • 2
  • ›

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

25 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 avatar image avatar image avatar image avatar image

Related Questions

Getting instance of an sub object rather than the original's subobject 0 Answers

Renaming Child Objects during Instantiate? 1 Answer

Instantiate Terrain Object as child of Empty Game Object 1 Answer

[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer

Smart way to add border to a text mesh in a 2d environment 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