- Home /
The question is answered, right answer was accepted
Is it bad to have many object in the scene with Lateupdate function checking player position
Hello, I have a question about performance. My game is going to have many objects in the scene. I have made a script but I m not sure if the way I did is the best one. In the script I wrote in LateUpdate check player position if player comes near 20f, set active mesh renderer of this object. If the player. position is more than 30f disable mesh renderer. the thing is I m going to have like 200 or more object in the scene and every single object is going to have this script attached would that be bad for performance ?
Answer by JonPQ · Jan 07, 2019 at 11:19 PM
Sounds like you are doing some LOD on those models in your scene so its not drawing too many of them. UNity has a built-in system for handling LOD, you can use that if you like... see here... https://docs.unity3d.com/Manual/LevelOfDetail.html
another alternative is to have a manager... with a list of all our objects to check ranges. Then just have that one manager script run through loop of all the checks at the same time in a loop. which should be faster (and avoid the issue of objects turning themselves off when far, then not being able to turn themselves back on when close. (because they are off, and code isn't running))
Thanks for the advise. I have done some research and aslong the game does not show some issues like lagging or overheating, I will continue making it this way, the LOD answer is great but I think not needed because the player controlls the mesh renderer of all the enemie objects in the scene when they are away, their mesh renderer is kept off and player comes near 20f they get activated and show them. Btw this is a mobile game for android and ios.