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 qwertyk31 · Nov 16, 2013 at 09:47 AM · javascriptgameobjectactive

Set child gameobject active?

How can you set the child of a gameobject active I have tried

 gameObject.transform.child.gameObject.SetActive(true);

But I get the error

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) BuildZone.Update () (at Assets/my assets/Scripts/BuildZone.js:24)

the script was attached to the parent of the object I was trying to make active How can I make the object active?

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

Answer by ArkaneX · Nov 16, 2013 at 10:57 AM

Transform has no child property, so this should not even compile...

To access children of a Transform, please use:

 for (var child : Transform in transform)
 {
     if(....) // check if this is the child you want to activate, by name, tag or anything else
     {
         child.gameObject.SetActive(true);
     }
 }

If you have one child only, then of course you can skip the if statement. You can also access a child by its index using GetChild method.

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 qwertyk31 · Nov 16, 2013 at 11:20 AM 0
Share

Assets/my assets/Scripts/BuildZone.js(24,33): BCE0005: $$anonymous$$ identifier: 'child'. is this C#?

avatar image ArkaneX · Nov 16, 2013 at 11:52 AM 0
Share

Nope - it's javascript. Could you post related lines from your code?

avatar image qwertyk31 · Nov 16, 2013 at 07:45 PM 0
Share

here is part of the script

 function Update () 
     {
         if(inBuildZone)
         {
             if(INV.sticks >= 30 && Input.Get$$anonymous$$eyDown ("r"))
                 {
                      Debug.Log("Build house");
                     child.gameObject.SetActive(true);
                 }
         }        
     }
 

the Debug.Log is called. does it matter if the game object with the "child.gameObject.SetActive(true);" is also a child?

avatar image ArkaneX · Nov 16, 2013 at 08:28 PM 0
Share

Did you declare/assign child variable? In the sample code from my answer, child is both declared and assigned as part of for loop.

And regarding your question - it doesn't matter.

avatar image qwertyk31 · Nov 16, 2013 at 08:45 PM 0
Share

Thanks it works now

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

18 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

Related Questions

Referencing children of an instantiated object. 1 Answer

Trouble getting GUI phone to open/close 1 Answer

How to create an 3d game object in 300 X 250 size? 1 Answer

Scripts wont work if deactivated then activated? 0 Answers

Disable/Enable Script or Add/Remove? 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