Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Disable Parent GameObject rendering

Discussion in '2D' started by nicciSixx, Jun 24, 2020.

  1. nicciSixx

    nicciSixx

    Joined:
    Apr 5, 2012
    Posts:
    9
    I have a complex canvas structure with UI elements - I would like to be able to quickly switch them in and out of visibility - but I don't want to call setactive - because I still want their monobehaviour functions called and I also want then to receive event calls.

    I thought about added canvasrenderer components at the level i would like to hide from - but there doesn't seem to be a a property that would toggle the rendering of the items.

    Is there any way for me to do this? Really appreciate the help.
     
  2. Neomedus

    Neomedus

    Joined:
    May 14, 2020
    Posts:
    47
    this.gameObject.GetComponent<SpriteRenderer>().enabled = false;
    this.gameObject.GetComponent<SpriteRenderer>().enabled = true;

    Would this work?