Skip to content

Camera.main is inefficient in frequently called methods

Vladimir edited this page Dec 7, 2018 · 15 revisions

This inspection will add higlighing if the Camera.main property is accessed in a performance critical context. The Camera.main property returns the first camera that is tagged with "MainCamera". Internally, it does this by calling FindGameObjectsWithTag, and doesn't cache the result, so accessing this property frequently will have an impact in performance. Consider caching the camera in a field, and setting value in Start or Awake.

See the documentation for Camera.main and also th support document "Camera.main is slow".

History:

  • The inspection has beed updated in Rider/ReSharper 2018.3 (as part of performance critical context)
  • This inspection was first added in Rider/ReSharper 2018.2
Clone this wiki locally