UI Element not turning on with SetActive(true)

if (CanvasEnabled) {
GameObject Healthbars = GameObject.FindGameObjectsWithTag (“playerCanvas”);
for (int i = 0; i < Healthbars.Length; i++) {
Healthbars .SetActive (true);

  •  		}*
    
  •  	} else {*
    
  •  		GameObject[] Healthbars = GameObject.FindGameObjectsWithTag ("playerCanvas");*
    
  •  		for (int i = 0; i < Healthbars.Length; i++) {*
    

_ Healthbars .SetActive (false);_
* }*
* }*
The Healthbars do turn off but not on again. Any ideas? I tried Getcomponent().enabled = true too but that didnt work either.

You cannot using any Find method to get inactive objects. It is not a good idea to be running FindGameObjectsWithTag so frequently anyway. Unless that array of healthbars is going to change you should cache the reference on start.

    private GameObject[] healthBars;

    void Start()
    {
    healthBars = GameObject.FindGameObjectsWithTag ("playerCanvas");
    }

That way the reference to the gameobjects will be stored and you can just use set active on them whenever needed.

You might want to group all the healthBars under an empty gameobject as a parent though and just set it to active/inactive. It will be faster and avoid running that loop.