Sorry if this is a dumb question or is obvious, I am still learning this stuff. I have a scene with many active game objects with scripts attached, schools of fish to be exact. Ideally I would like a lot of these in my scene, but since I am working with the Oculus I need it to be as efficient as possible. Even when these fish schools are culled they still seem to be a drain on the CPU, probably because they still have active scripts attached to them telling them to swim around and stuff.
So the only solution I can come up with is to try to activate them/ de-activate them as I move away from them. I want to put sphere colliders around them and make them a trigger, something like this
void OnTriggerEnter(Collider other)
{
GameObject.FindWithTag ("FishSchool");
if (other.gameObject.tag == "FishSchool")
{
other.gameObject.SetActive (true);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "FishSchool")
{
other.gameObject.SetActive (false);
}
}
I know the tutorial say you cannot re-activate a gameobject after de-activating using the gameObject.SetActive function it but I have been trying to find a workaround with no luck. I thought maybe if I tried activating it from another script that is attached to the player it may work, but it doesn’t. It will de-activate the gameObject but not turn it back on again. I think I could use instantiate or make them all child objects, but the problem with that is each one is unique, it is not like some generic zombie where you spawn a thousand of them and they are all the same. I suppose it could be done if I made 40 or 50 spawn scripts for each one and that seems like a lot of work and would that also be a burden on the computer?
So is there any obvious or clever work around this that I am missing?