Hi,
Found an excellent post about checking “Is target in view frustrum”. If i understand it correctly, we would stop rendering of an object by disabling its Renderer when off screen. But as soon as i do this …
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void OnBecameInvisible() {
GetComponent<MeshRenderer>().enabled = false;
}
void OnBecameVisible() {
GetComponent<MeshRenderer>().enabled = true;
}
}
… and the object leaves camera frustrum, Its Renderer does not dispatch OnBecameVisible again, once it later again enters the camera frustrum - well, thats obvious, since we disabled it in the first place - so a disabled Renderer would not fire OnBecameVisible.
What gives? Using this culling technique i cant do the culling.
Further more i wanted to actually disable the whole GameObject (not only its Renderer) when it leaves frustrum. Any thoughts on the best-practise implementation-vise here? I guess you cant use Renderer’s isVisible/OnBecameVisible/OnBecameInvisible? Is using WorldToScreenPoint favored approach in this case? Is there better approach than disabling whole GameObject performance-vise?
Brainstorm please, tested methods preferred!
@Baste "As with everything that's performance related, optimizing before you know what's causing bad performance is the stupidest thing you can do" Well said x) My case is primitive objects with colliders and scripts on them, its that simple. Ive noticed full screen of these runs well. Other 2 full screens of them off camera and it runs pretty bad. Must be the active Scripts like Monobehaviours waiting for Collider triggers etc eating empty CPU cycles on every frame. Thanks for the examples with projector and navmesh, might be useful later.
– _watcher