Home > Enterprise >  Unable to activate a previously deactivated gameObject (canvas) in Unity
Unable to activate a previously deactivated gameObject (canvas) in Unity

Time:12-05

For some reason Unity won't activate my Death Screen GUI-canvas after the player has died (or the GameObject of the player has been destroyed, or the GameObject == null). I'm able to deactivate it, but activating it after doesn't work for some reason. I get no error, so I have no idea what's wrong. Here's the code in question:

public class DeathScreenMaster : MonoBehaviour
{
    public GameObject player;

    // Start is called before the first frame update
    void Start()
    {
        gameObject.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            gameObject.SetActive(true);
        }
    }
}

CodePudding user response:

You can't activate the game object by itself because it's already deactivated and Update() method is not executing anymore. You have to have some other object that controls this object (DeathScreenMaster) activation and deactivation.

  • Related