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 wildlo931 · Aug 09, 2017 at 01:44 PM · instantiatechildclone

instantiated Gameobject trying to access child of child which is a clone itself.

i am trying to access child of child which is a clone itself. tried every possible way but in vain. alt text

alt text i have tried i adding code also here i have commented the problem infront of each line .

 public GameObject test;
 private Transform[] target;
 public Transform [] checkpoints;
 public GameObject[] instantiate_cars;
 public int get_pref_int_car;
 public int get_pref_int_color;
 // Use this for initialization
 void Awake()
     {
 get_pref_int_color = PlayerPrefs.GetInt ("colorcar");
 get_pref_int_car = PlayerPrefs.GetInt ("CarSelected");
 GameObject childObject = Instantiate (instantiate_cars [get_pref_int_car]) as GameObject;
 childObject.tag = "myplayer";
 Debug.Log(""+childObject.transform.FindChild ("Chassis Joint(Clone)").transform.GetChild (0).name); // tried this null refrence
         //childObject.transform.GetChild(8).transform.GetChild(0).transform.GetChild(0).GetComponent<MeshRenderer>().material.mainTextureOffset = ColorPicker.coloroffsets_pass[get_pref_int_color];    // out of ondex
 target = GameObject.FindWithTag ("myplayer").GetComponent<CarCheckpoint> ().checkPointArray;
 target [0] = checkpoints [0];
 target [1] = checkpoints [1];
     }
 void Start () {
 Debug.Log ("" + GameObject.FindWithTag ("myplayer").transform.GetChild (7).name); // null refrence
 Debug.Log ("" + GameObject.FindWithTag ("myplayer").transform.FindChild ("Chassis Joint(Clone)").name); // null refrence
     }



Any suggestions ,

untitled1.png (168.7 kB)
untitled.png (174.9 kB)
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

2 Replies

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

Answer by wildlo931 · Aug 10, 2017 at 06:07 AM

So People after a long wait and nobody replying i finally got over the problem , u should never access a child based on its placement in a cloned / instantiated object because sometimes they have extra component which may not be part of your prefab , so write the code on the bases of where your child was present in the original object that was instantiated for example ...

My clone had the chassis child on index 9 and that was not present any where that is why it was returning null , i could view on the 9th index but it was virtually there , so in my original prefab the chassis child was on index 0 , so when i did this ....

childObject.transform.GetChild(0).transform.GetChild(0).GetComponent().material.mainTextureOffset = ColorPicker.coloroffsets_pass[get_pref_int_color];

It worked like Magic........

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
0

Answer by wildlo931 · Aug 09, 2017 at 01:47 PM

@Mike 3 @Bunny83 @robertbu @Aurore @clunk47 suggestions

Comment
Add comment · Show 3 · 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 wildlo931 · Aug 10, 2017 at 05:08 AM 0
Share

@Owen-Reynolds @aldonaletto @fafase @Fattie @Wolfram

avatar image wildlo931 · Aug 10, 2017 at 05:11 AM 0
Share
 //        test = transform.Find ("Car1P-1(Clone)/Chassis Joint(Clone)/Chassis/Body_20");
 //        if (test == null) {
 //            Debug.Log ("nothing was found");
 //        }

tried this also not working

avatar image wildlo931 · Aug 10, 2017 at 05:14 AM 0
Share

i am unable to understand why a cloned object will have a cloned child ......

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

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

Related Questions

Destroy One Child, Not All 2 Answers

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

Making a Clone a Child of Another Object 1 Answer

How can I make a game object follow an instantiated game object? 1 Answer

Prefab clones behaviour 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