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 AlanChatham · Sep 22, 2011 at 06:53 AM · disabledgameobject.active

Can a disabled GameObject re-enable itself?

Simple question, but I'm just looking for confirmation - if I disable an object by calling

GameObject.active = false;

is there any way to get it to re-activate itself in a script on the disabled gameobject itself (maybe via a coroutine or some exotica)? I'm guessing the answer is no, but I wanted to get some feedback (the documentation on .active is pretty sparse...)

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

3 Replies

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

Answer by Kourosh · Sep 22, 2011 at 07:19 AM

I think your guess is correct. No, once the gameobject is deactivated the only way to activate it again is to store an instance of it in a GameObject variable and activate/deactivate using that variable.

Comment
Add comment · Show 2 · 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 AlanChatham · Sep 22, 2011 at 07:24 AM 0
Share

Thanks! $$anonymous$$aybe I'll just write something ugly and gross that turns off all the components of an object and all its children.....

avatar image AurraSing · Jun 23, 2019 at 07:08 PM 0
Share

No, this answer is actually wrong, see correct one below

avatar image
2

Answer by mrDude · Sep 22, 2011 at 08:27 AM

You should actually notice that when you use Active on components Unity actually throws out a warning at the bottom of your screen saying you should not do this on components but rather use enabled on the gameObject itself.

In all honesty this whole active/enabled thing is really causing me a lot of fuss. i have a component I want to use only at certain times and others that should be active all the time. Thus, dialling the game object makes no sense so I still disable/enable the component and it works fine. I just hope that Unity doesn't one day say "it's been depreciated for a long time now, so now we are not going to allow it any more" cause then I'll be in trouble.

I have found, though, that if you set enabled to false on a gameObject, the contained components are still active and still update my GUI and everything. Really, this whole enabled/active thing really is a pain.

One more example... If you drag a game object onto a script so it can be referenced in the game, but that object starts out disabled, then you will get a runtime error when you try to enable it. Also, if you have a disabled item and you do a gameObject.Find("child1") it will not find it so you are not able to activate it that way...

My solution has always been to either drag the child game object to a reference field or to have the script do a .Find() operation and once that is done, I disable it during the parent's Start() function. Not being able to locate a disabled child object at runtime tends to complicate things a tad...

Comment
Add comment · Show 1 · 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 tubelightboy · Jul 04, 2021 at 06:57 PM 0
Share

https://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html This might be an interesting read for checking if the child is active or inactive because of the parent game object.

avatar image
1

Answer by AurraSing · Jun 23, 2019 at 07:10 PM

You can enable your gameobject using: Invoke or InvokeRepeating

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ReEnableSelf : MonoBehaviour { // Start is called before the first frame update void Start() { InvokeRepeating("reEnableSelf", 3f, 3f); }

void reEnableSelf() { gameObject.SetActive(!gameObject.activeSelf); if(gameObject.activeSelf) { Debug.Log(gameObject.name + " is active!!"); } }

}

Comment
Add comment · Show 1 · 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 tubelightboy · Jul 04, 2021 at 06:46 PM 0
Share

yeah but what if it's the same object that has to reenable or re-activate itself. when the object is disabled, so is the script. this won't help imo.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Is LateUpdate() always called, even if the script is disabled in the Inspector? 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