- Home /
Disable objects far away from player to make performance better
Hello guys, I am making a plataformer game and I was thinking, if the object (like an enemy) is too far away from the screen, there is no necessity to it execute any function like animate or move.
I am planning to create a game level that the player will need more than 6 minutes to go until the end. Therefore will be a lot of objects (scenario objects, enemies, traps, etc). So anyone know a good way to disable an object until the player enters in the object's action radius.
For now, I am thinking to make a general script that uses a circle trigger collider, while the player is not inside of it, it will get all the components from the object(except this script component) and its children and disable then. What do you think? Thanks.
Answer by Berenger · Feb 19, 2012 at 03:54 AM
Two words : OnBecameVisible and OnTriggerEnter.
Hmmm using OnTriggerEnter, if I have, for example, 200 objects with a circle trigger collider, is this too heavy to the engine process the OnTriggerEnter check for every object?
Not if you are running on pc/mac. For mobile though, you might need to group those objects, like one big trigger for 50 objects, if they are close enough. Anyway, if you disable the trigger when the item exit the camera frustrum, you won't have all of them (OnBecame(In)Visible).
Answer by zeuo · Feb 19, 2012 at 05:17 AM
try desabbeling the mesh render i made a reallly big and detailed forest so i made a script that disables the mesh render until the player is close to it
But the things in Unity are only rendered when they are closer than the far clipping distance from camera or something like this?
Your answer
Follow this Question
Related Questions
Increase Unity2D editor performance 0 Answers
Most performance friendly way to "unrender" a GameObject? 6 Answers
2D Android game - bad performance after launch 1 Answer
Object.get_name() performance 0 Answers