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
0
Question by Jan_Julius · Oct 14, 2014 at 10:09 AM · parentchildchildrenfind

(C#) How do I run something in my child's script?

I've tried a few things but I can't seem to figure it out

this:

 hex = transform.FindChild("Hex").GetComponent<Hex>();

Doesn't seem to do it either, am I doing something wrong?

I want to run something in my child's script, how do I access it and run it?

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

Answer by MrSoad · Oct 14, 2014 at 10:15 AM

Try this, I've split it into two lines to make it easier to read.

 oChild_Object = transform.parent.FindChild("Child_Object_Name").gameObject;
 oChild_Object_Script = oChild_Object.GetComponent(Your_Child_Object_Script_Name);

No quotes on the script name, just the name exactly as is exculding the ".js" . Hope this helps

Comment
Add comment · Show 5 · 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 MrSoad · Oct 14, 2014 at 10:18 AM 0
Share

Oh, declare your script variable like this :

 private var oChild_Object_Script : Your_Child_Object_Script_Name;

avatar image MrSoad · Oct 14, 2014 at 10:22 AM 0
Share

This works even if it's not in the reference.

avatar image Jan_Julius · Oct 14, 2014 at 11:19 AM 0
Share

I'm sorry I use C# and trying to convert this it doesn't work.

avatar image MrSoad · Oct 14, 2014 at 11:20 AM 0
Share

Sorry, I don't know C# well enough to convert this...

avatar image Jan_Julius · Oct 14, 2014 at 11:26 AM 0
Share

No problem, thanks for the effort :).

avatar image
0

Answer by tanoshimi · Oct 14, 2014 at 10:18 AM

FindChild is not a method of Transform (I think it may have been some time ago, but it's certainly not in the method reference now.). Try Find instead.

Otherwise, if the GO to which this script is attached has a child called "Hex", and that child has a script attached called Hex, this should work. If you only have one child object with a Hex script on it, you could also try

 hex = GetComponentInChildren<Hex>();



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

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

28 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

Related Questions

Make a simple tree 1 Answer

find ALL children of a parent 1 Answer

How To Get List of Child Game Objects 14 Answers

accessing all of a colliders parents children 1 Answer

Finding child problems.. 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