- Home /
Don't update gameObjects too away from player.
So lets say my game project will have a very heavy amount of GameObjects for whatever reason. Dunno, 50000.
Each object has the next components: RigidBody, Mesh Renderer, Box Collider, and a simple script.
Considering the amount of objects, it makes sense to only "work" on the objects that are close to the player, in X range.
So my first idea was to use Vector3.Distance to check the distance from this gameObject to the player's transform (this guy is a first person controller). However I decided not to do so because I though that calling Vector3.Distance 50000 times per frame was just too much. Also because I have this other issue where for some reason the position of the player is not updating: http://answers.unity3d.com/questions/28547/transform-position-not-changing
So, what's your idea?
When I figure out a good way to make my objects only "work" when they are close to the player, I will need to know.. how to stop the "work" thing lol. I guess disabling the components is a good start?
Answer by tchen · Dec 04, 2010 at 07:50 AM
Use a grid. Every object updates which grid cell they're on during their last updates. Then you only need to 'activate' those grid cells which are of interest. I'd go for a grid size about 2/3 of your lod range.
Your answer
Follow this Question
Related Questions
UI Text not displaying for some game objects when Player is within distance of the object 0 Answers
Best method to tile 3d platforms 1 Answer
Large # of gameobjects run smoothly or alternative? 1 Answer
Remove objects from list when they are out of range. 0 Answers
optimizing Gravitacional object-to-object calculations 1 Answer