Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Does Sprite Renderer have the isVisible property

Discussion in 'Editor & General Support' started by MrMajorThorburn, Dec 3, 2023.

  1. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    74
    I am trying to confirm that an instantiated instance of an animated sprite is visible on the screen but I am getting a false reading even when its at 0,0,0;
    I have looked at the documentation and cannot find it so if sprite renderer is not based on renderer how do I confirm the animated sprite is in view?

    Code (CSharp):
    1.  
    2. activeMyMouse = Instantiate(prefabs[direction],new Vector3(0,0,0),Quaternion.identity);
    3. Debug.Log("activeMyMouse position="+activeMyMouse.transform.position);
    4. myMouseRenderer = activeMyMouse.GetComponent<Renderer>();
    5. Debug.Log("renderer?"+myMouseRenderer);
    6. Debug.Log("activeMyMouse visible?="+myMouseRenderer.isVisible);
    7.  
    Screen shot attached.
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,129
  3. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    74
    I think the screen shot and code I supplied demonstrates that it does not work.
    Am I doing the code wrong?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,129
    I think the issue is that you test this right after instantiating the object. This means it hasn't been rendered at this point, which is probably why it's not visible (yet). You need to wait one frame to confirm that.
     
  5. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    74
    That was it. I put the Debug.Log in a function and used invoke with a delay.