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
1
Question by callen · Feb 24, 2014 at 10:55 PM · childrenparentingactiveupdate-order

After SetActive(false/true) scripts no longer update?

Hi, because of an issue I couldn't find a better answer for, I need to call this code each frame:

 gameObject.SetActive(false);
 gameObject.SetActive(true);
 

The problem is, script on children don't work afterward. Even though every game object has activeInHierarchy and activeSelf == true, and every script on these objects reports enabled == true, the Update functions on these scripts are not being called. Any script on the gameObject I'm changing (or its parents) works, but scripts on children stop working, yet say they're enabled.

Simplified version of what I'm doing:

 //Example Object
 //ParentObject (w/ ParentScript.cs)
 //   > ChildObject (w/ ChildScript.cs)
 
 //ChildScript.cs
 void Update() {
    Debug.Log("Child");
 }
 
 //ParentScript.cs
 void Update() {
    Debug.Log("Parent");
    //with these 2 lines, "Child" is never printed, without it is.
    gameObject.SetActive(false);
    gameObject.SetActive(true);
 }

I thought I understood all this active/enabled stuff, but I guess not yet.

Edit: Actually I have a hunch about this, but can anyone link to a reference about when objects are actually activated/deactivated? What if deactivating turns off the parent before the child scripts run, but only activates again after the next game loop starts - that would definitely cause it?

Comment
Add comment · Show 3
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 whydoidoit · Feb 25, 2014 at 03:57 AM 0
Share

No that should all work - and I'd be very surprised if it's generally broken because my stuff all seems to work and it wouldn't if that were broken for me... Are you sure something else isn't disabling them? Coroutines will have stopped running if you did that BTW

avatar image callen · Feb 25, 2014 at 04:41 AM 0
Share

The simple example worked for me too, only after exiting and restarting Unity though... ghosts, probably.

$$anonymous$$y main game code is still doing it, its a more complex GameObject and I'm making the SetActive calls at the end of my Update function, in a script attached to the top-level parent GameObject.

Basically my setup is like this (2d game):

 Parent (has script doing the SetActive calls)
 ->Head (Quad with image)
 ->Arm1
 --->Quad (w/ arm texture)
 ->Arm2
 --->Quad (w/ arm texture)
 --->Gun (Quad w/ texture and a GunScript)
 ->Leg1
 ->Leg2 (both Legs are Quad w/ Texture and LegScript so they move when walking)

I don't do anything in Coroutines except occasionally waiting for one-off sounds to destroy, and like I said I'm calling SetActive, twice in a row, right at the end of Update.

avatar image callen · Feb 25, 2014 at 05:06 AM 0
Share

I guess I found a 'solution' of sorts, except at this point I'm hacking a hack and it just feels like something is very wrong...

To fix my issue of "toggling active on a parent messes up children" I just do individual toggles on all the deepest descendants (actually just the two that I need the hack for), because toggling active in a script doesn't mess up itself or its siblings.

Yeah it's a terrible answer. Please please help me find a better one!

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

21 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

Related Questions

check a object is parent or not? 1 Answer

Parenting 1 object/Removing child/ pick up 1 Answer

Move parent pivot point along with child Rigidbody? 1 Answer

Why I have a 'lag' between parent and child ? 0 Answers

how can i make a player get in a vehicle? 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