Scene with 1000 + ridged bodys optimization help

Hello,

I’m hoping i could get a little help with some code that i cant seem to get to work.

First off, I have a scene that currently has 1000+ objects (Cans) that all have Ridgedbodys attached to the character can move them around and so on, its got to the point now where its starting to impact performance quite badly.

SO… i’ve thought to help this i’ve placed a sphere around the player that isn’t visible and currently have it set to Is Trigger, i attached the script below to the Cans but it doesn’t seem to do anything.

On the cans do i still need a Ridgedbody attached? or will this script do it for me?

var Can : GameObject;
 function OnTriggerEnter(Other : Collider){
 
 if(Other.gameObject.tag == "Player"){ //Be sure to tag your player to "Player"
 
 yourObject.rigidbody.enabled = true;
 
 }
 
 }

The two objects i have at the moment are:

Can - Can objects with a ridgedbody attached
Player - Invisible sphere with IsTrigger enabled

Thanks in advance for anyhelp :slight_smile:

I think First of all, you need to put the script on the player, tag your cans as Can and then check in the trigger event if(Other.gameObject.tag == "Can") this will get rid of 1000+ scripts on the cans (one on each).
Then what you can try to do is to disable the cans that are not in the view, that is, atleast disable the cans(or any other item) which is behind the player. Once that is successfully done, you can try to limit your view and disable more cans (or items that you can disable).

Hope this helps but do remove the script from cans because that way you have more than 1000 scripts which is obviously not very clever. Let me know if it works.