- Home /
Why isnt renderer.isVisible not working?
the script i have is:
void Update ()
{
bool isVisible = renderer.isVisible;
if (isVisible)
{
renderer.enabled = true;
}else{
renderer.enabled = false
}
}
my question is, How come this script isnt working?
The biggest question I have is why. What effect are you trying to achieve?
Answer by robertbu · Jun 22, 2014 at 02:43 AM
Thoughts:
Unity already does this kind of culling, so all you are doing is adding more overhead.
Any object with the renderer turned off is not considered visible even when it is in the view area of any camera.
Note isVisible is true when seen from any camera. Back in 3.x days that included the scene camera when in the Editor. That may still be true.
So do you have any ideas on how I can accomplish turning on and off the renderers if they are in view?
@theacesofspades: Don't bother. There's no reason to do this. Your script can't possibly work anyway because you turned the renderer off when not visible, so it would never turn back on again. Even if it could, polling .isVisible every frame isn't very efficient when you could use OnBecameVisible and OnBecameInvisible.
Ok but I used on became invisible and on became visible but how can I hide the objects that are not seen by camera? Because the game is too laggy since I have a ton of objects in the scene.
Unity already hides objects that are not seen. You don't have to do anything. If the game is laggy because you have too many objects, then reduce the number of objects. That's a completely separate issue.
$$anonymous$$inecraft-line games use voxels. That is they construct many cubes using a single mesh. Using separate game object for each cube will kill your frame rate. Lots of posts on UA on voxels.
Your answer
Follow this Question
Related Questions
Renderer on object disabled after level reload 1 Answer
camera.enabled = true not working? 0 Answers
Checking if GameObject is rendered by specific camera 1 Answer
Multiple Cars not working 1 Answer