- Home /
 
               Question by 
               MhdAmine · Apr 15, 2021 at 07:03 PM · 
                collisioncolliderperformancecomponent  
              
 
              Performance: Addcomponent BoxCollider in update method
Hello,
I have 10000 GameObjects (non-moving objects) that I instantiate in unity.
Which is better in terms of performance:
- Add a BoxCollider to all objects when instantiated 
- Add BoxCOllider to the objects when the camera is close to the object using the update method - private void FixedUpdate() Vector3 CameraPos = mainCam.transform.position; Collider[] colliders = Physics.OverlapSphere(CameraPos, radius); foreach(Collider hit in colliders) { if (hit.gameObject.GetComponent<BoxCollider>() == null) { hit.gameObject.AddComponent<BoxCollider>(); } } }
I need BoxCollider because the camera should not go through these gameobjects.
- Target platform: Mobile phones 
- Performance concerns: 
- Ram: adding multiple components 
- CPU: adding BoxCollider component at runtime 
Which one is better?
Thank you very much.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                