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 JamesGryphon · May 25, 2017 at 02:53 PM · if-statementschildrensetactivetransforms

Particular Child Object Refuses to setActive - Others work fine

I could probably just do this some other way. Maybe I will end up doing so (I suspect this setup is subpar to begin with). That said, I'm ticked off enough by the opaque nature of the problem that I thought I'd submit it here in the hopes that someone might recognize where the trouble's coming from, and help me to clear it up, just for the satisfaction of ridding a bug from the world.

I have child objects in my 2D ship that're used as engine flame animations. There's currently separate forward and rear animations that play depending on which direction the player is thrusting, and normal and 'afterburner' or "boosted" sets, for a total of four different animations to keep track of.

Three of the four work fine. One of them (activated by the section which I have placed asterisks around here for the purposes of easy identification) doesn't show up at all, for no apparent reason. If I switch it to use any animation besides the one that is relevant to the situation (like using the boosted thrust for both normal and boosted) that works just great. The only thing that doesn't is the one that is supposed to be there. I've used print statements to show that it does access that code, it just doesn't turn the child object on. I've switched the code around (a previous iteration was written just about upside-down from this) to test whether anything was wrong with that animation, but no, it's fine -- it just doesn't get loaded by that particular segment of code.

Have a look at this mess:

     void EngineActivate()
     {            
         if (boost == 0) {
             if (vert > 0) {
                 transform.GetChild(0).gameObject.SetActive (true);
                 transform.GetChild(1).gameObject.SetActive (false);
             } else
                 **transform.GetChild(2).gameObject.SetActive (true);
             transform.GetChild(3).gameObject.SetActive (false);**
         }
 else if (vert > 0) {
                 transform.GetChild(1).gameObject.SetActive (true);
                 transform.GetChild(0).gameObject.SetActive (false);
             } else
                 transform.GetChild(3).gameObject.SetActive (true);
             transform.GetChild(2).gameObject.SetActive (false);
             }


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 ShadyProductions · May 24, 2017 at 08:33 AM 0
Share

Try setting them up as variables and reference them in the inspector public Transform child1; etc and see if it works, it might be that the GetChild method returns a null

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Foreach loop trying to grab all children in scene 1 Answer

SetActive not working 2 Answers

Gap in requirements in GUI based game 2 Answers

How do you enable/disable a child object individually? C# 1 Answer

How to access children in script attached to gameObject 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