Hey. I want to delete a gameobject after it is not visible by the camera anymore.
I know this kind of question got asked a lot, but it no method seems to work for me.
Please help me.
Thanks.
Hey. I want to delete a gameobject after it is not visible by the camera anymore.
I know this kind of question got asked a lot, but it no method seems to work for me.
Please help me.
Thanks.
Hi, this seems like a robust answer:
Once detected, follow with a simple GameObject.Destroy.
Some potential problems to look out for were discussed here:
You can use IsVisible: Unity - Scripting API: Renderer.isVisible
NOTE: IsVisible is called by the Editor camera as well. Even if the object isn’t visible in the Game View, if it’s visible in the Editor, it will be marked as visible. Really strange, but someone at UT thought that was a great idea.
I have a problem with my scene. I created a cube and made it into a platform and I created another cube for the player but then it can’t be seen in my scene but it can be seen in my camera . please help me
How is this not a bug XD, is the dumbest logic ever> tx for letting us know. Should b raised as bug IMO
Use this code;
//Attach this script to a GameObject with a Renderer component attached
//If the GameObject is visible to the camera, the message is output to the console
using UnityEngine;
public class IsVisible : MonoBehaviour
{
Renderer m_Renderer;
// Use this for initialization
void Start()
{
m_Renderer = GetComponent<Renderer>();
}
// Update is called once per frame
void Update()
{
if (m_Renderer.isVisible)
{
Debug.Log("Object is visible");
}
else if (!m_Renderer.isVisible)
{
Debug.Log("Object is no longer visible");
}
}
}
Just bringing this issue back to the forefront. I’m about to test this out and then may submit a bug report within Unity.
ADDITION: Alright I’ve tested this and found it only reports the game’s camera while in the Game view, but reports the scene camera while in the Scene view. Which isn’t quite as bad as it sounded at first (it’s not any time in the editor, only while in the scene view) but still renders this command basically useless.
Instead, I found this frustum planes method that seems to work very well:
isVisible wasn’t working for me and I was trying to figure out why for hours. I can’t believe the editor window was why. Thank you so much.