# gameObject.SetActive (true); Not working

**URL:** <https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966>\
**Category:** Questions & Answers\
**Created:** [March 14, 2017, 5:30pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966 "2017-03-14T17:30:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![calum1904](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@calum1904](https://discussions.unity.com/u/calum1904)\
**Post date:** [March 14, 2017, 5:30pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/1 "2017-03-14T17:30:44Z")

</div>

So I am making a game over UI and setting the game object that it’s in at to inactive when I start the game but I can’t get it to reactivate.

```
public class gameManager : MonoBehaviour {

	public GameObject gameOverUI;

    void Start () {

		Debug.Log ("turn off ui");
		gameOverUI.SetActive (false);

	}

public void gameOver(){

		Debug.Log("GameOver");
		gameOverUI.SetActive (true);
	}

```

This is a condensed version of my gameManager code, both of the Debugs are printing and when I have the gameObject on it disappears when I start the game so it must be linked correctly. I just can’t get it to show again. Anyone know why?

---

<div class="post-metadata">

**Author:** ![MeronSoda](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MeronSoda](https://discussions.unity.com/u/MeronSoda)\
**Post date:** [March 15, 2017, 3:35pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/6 "2017-03-15T15:35:28Z")

</div>

The “gameOver” function must be a **callback** from an **active** object.  
So… Is the object that calls this function activated?

For instance, if the “gameOver” callback is running from an **Update** function from an **INACTIVE** object, it won’t be called.

---

<div class="post-metadata">

**Author:** ![body](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@body](https://discussions.unity.com/u/body)\
**Post date:** [March 16, 2017, 8:29pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/5 "2017-03-16T20:29:06Z")

</div>

Hi! I had same problem, but i found why this is happens.

1. You made GameObject in design time.
2. Made it inactive.
3. Start play
4. GameObject is still inactive.
5. You call gameOver()
6. GameObject activates first time
7. Unity calls Start() method (because script activate first time.). GameObject deactivated again.

So! You have two variants:

1. Makes GameObject initially as inactive (in Design Time) and remove deactivation from Start() method.
2. Makes GameObject initially as active (in Design Time) and keep deactivation in Start() method.

Good luck.

---

<div class="post-metadata">

**Author:** ![Matt1000](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Matt1000](https://discussions.unity.com/u/Matt1000)\
**Post date:** [March 16, 2017, 4:25pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/2 "2017-03-16T16:25:42Z")

</div>

Your code seems to be perfectly ok. The only posible problem i can imagine of is a hirerchy problem. If you have a parent/grandparent GameObject disabled, this fact will have prority and the GameObjectt you want to activate wont. Perhaphs [this](http://answers.unity3d.com/questions/1086238/activatingdeactivating-gameobject-not-working.html) can help you.

Otherwise check if your code depends on that other object. But i **dont think** it’s the case scince you are using a game manager.

---

<div class="post-metadata">

**Author:** ![KrazyApple](https://avatars.discourse-cdn.com/v4/letter/k/f9ae1b/32.png) [@KrazyApple](https://discussions.unity.com/u/KrazyApple)\
**Post date:** [March 15, 2017, 2:21pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/3 "2017-03-15T14:21:43Z")

</div>

Hello , Did you check the call of your function gameOver ?  
Or maybe you setActive(false) the gameOverUI after the function or in others scripts ?

---

<div class="post-metadata">

**Author:** ![joshua-lyness](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@joshua-lyness](https://discussions.unity.com/u/joshua-lyness)\
**Post date:** [March 15, 2017, 2:28pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/4 "2017-03-15T14:28:45Z")

</div>

I might be wrong, but surely if you have a script on an inactive gameObject, that script won’t be running?

From the looks of your code, the GameOverUI is a variable, so if you had a manager object separate from the UI object then it would run fine, however you say in the question “the game object that it’s in”, so thought it was worth checking.

If it was the latter, make a new gameObject that is always active, and move the script onto that. It can be a “manager” object that handles activating UI and so forth. Just a heads up as well, if you want to access the gameObject that a script is attached to, “gameObject” can be used instead of making a variable to hold itself. 🙂

---

<div class="post-metadata">

**Author:** ![PremiereBoris](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PremiereBoris](https://discussions.unity.com/u/PremiereBoris)\
**Post date:** [March 15, 2017, 3:30pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/7 "2017-03-15T15:30:02Z")

</div>

Make sure this script is not attached to the disabled object.

---

<div class="post-metadata">

**Author:** ![rhylvin2016](https://avatars.discourse-cdn.com/v4/letter/r/c57346/32.png) [@rhylvin2016](https://discussions.unity.com/u/rhylvin2016)\
**Post date:** [March 17, 2017, 2:42am UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/8 "2017-03-17T02:42:19Z")

</div>

why not just put the gameOverUI to be inactive at the hierarchy… you won’t need that void Start() anymore.

---

<div class="post-metadata">

**Author:** ![CazualNoob](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@CazualNoob](https://discussions.unity.com/u/CazualNoob)\
**Post date:** [June 6, 2018, 1:12pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/9 "2018-06-06T13:12:46Z")

</div>

Make sure you dragged and dropped from the hierarchy instead of the prefab onto your component.

---

<div class="post-metadata">

**Author:** ![lucassivolella](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@lucassivolella](https://discussions.unity.com/u/lucassivolella)\
**Post date:** [August 13, 2020, 6:38pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/10 "2020-08-13T18:38:05Z")

</div>

I have the same problem. My GameOverUI Panel won’t activate when I call the GameOver method, although the method is running (I checked with Debug.Log). I tried another UI Panel on this same method and it did not open either.

I tried opening the GameOverUI Panel on my Victory method and this time it worked.

I have reread my code a thousand times, but I cannot see where the mistake is. The most annoying thing about all this is that the GameOverUI was one of the first things I created in the project and it was working just fine in the beginning.

```
public void GameOver()
{
    Cursor.visible = true;
    gameOverPanel.SetActive(true);
    Debug.Log("Game Over.");
    Time.timeScale = 0;
}

public void Victory()
{
    Cursor.visible = true;
    victoryPanel.SetActive(true);
    Time.timeScale = 0;
}

```

---

<div class="post-metadata">

**Author:** ![harisriazgondal](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@harisriazgondal](https://discussions.unity.com/u/harisriazgondal)\
**Post date:** [August 23, 2021, 6:17pm UTC](https://discussions.unity.com/t/gameobject-setactive-true-not-working/183966/11 "2021-08-23T18:17:49Z")

</div>

i may be wrong but u have to use some kind id of “” if ""statement to make it work  
like in my  
if (gameover = anything)

{  
gameOverUI.SetActive (true)  
};

then its going to work fine
