Deactivate all gameobject's script within a distance of you?

So I’m working on an open world game, and like all open world games, you have to cut back somewhere to make sure it runs well. Problem is, despite a lot of research, i have no idea how to do this. So, how would I make a trigger collider, that when entered, it turns all of the gameobject’s scripts on, and when left, turns it off if it’s already on.

So I don’t want to make it for each individual object, I already know how to do this, and it isn’t at all efficient, just so that anytime the player walks into an area, if a giant box collider trigger hits another object, it turns on that other objects scripts automatically.

Any help would be awesome, even just pointing me in the right direction. I’m stumped, sorry for the vague description,
Thanks,

http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html[http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html](http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html)

it’s pro only but I think there is a free or at least cheaper asset in the store that does it.

Looks like you’re confused about what occlusion culling really does. Also, OP isn’t asking for this.

Make an open-world game isn’t easy, there are a lot of uncovered topics. If you plan to go further, you should master more Unity knowledge before, so if you’re asking this question probably you should aim for smaller games to gain more skill. Just a friendly advice.

I really dont know if this is what you meant: InstantOC …only 15$ …however if you wish to make it yourself, i believe InstantOC use raycast to check how far or visible objects are …but this could also work: Unity - Scripting API: Physics.SphereCast

As I said before, occlusion culling has nothing to do by activating or deactivating scripts, so isn’t related to OP question.

Occlusion Culling is a feature that disables rendering of objects when they are not currently seen by the camera because they are obscured by other objects. First line at: http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html

I would go for something like this. Make a gameobject with a sphere collider/trigger the size of the area/chunk you want to enable/disable at once. Attach a script to this gameobject. On Start() you make a call to Physics.OverlapSphere to find all the gameobjects in the desired area and store them in an array for later reference. Iterate through the array and set every object to inactive. Place instances of this gameobject all over your world. In OnTriggerEnter with your Player Character you enable all the gameobjects in the array, in OnTriggerExit disable them… that should do it.

I don’t mean to sound over confident. But It’s a team of 4 and I’ve worked with unity for around 4 years now, I just never ventured beyond what I needed to know. But thanks, I do always get a bit upset at the people with such huge ambition and so little experience. I’m not being unreasonable, I’m not trying to make Grand Theft Auto 5, but I do need a big environment.

And yes, we already have Unity Pro, and Occlusion Culling is necessary, but doesn’t really help what I’m trying to achieve.

This is what I was thinking, but, I need the objects to be visible, so it can’t be enable/disable. It just needs to activate/deactivate the scripts.

Thanks,

once you have the name of the gameobject from the collision function,
you might be able to do something like this

GameObject.Find("NAMEHERE").GetComponents<MonoBehaviour>().enabled=false;

Haven’t tested that, but it might work

Never ever, ever, ever use GameObject.Find where you can help it.

Sounds like you’re after OnBecameVisible and OnBecameInvisible.

That’s just slightly different. Instead of setting the gameobject active or inactive you would just use something like this

private Collider[] YourCachedCollidersArray;
	
	void Start() {
		YourCachedCollidersArray = Physics.OverlapSphere(transform.position, 100f);
	}
	
	void OnTriggerEnter(Collider hit) {
		foreach(Collider c in YourCachedCollidersArray) {
			c.gameObject.GetComponent<TheScriptYouWantToControl>().enabled = true;
		}
	}
	
	void OnTriggerExit(Collider hit) {
		foreach(Collider c in YourCachedCollidersArray) {
			c.gameObject.GetComponent<TheScriptYouWantToControl>().enabled = false;
		}
	}