-
Notifications
You must be signed in to change notification settings - Fork 135
Camera.main is inefficient in frequently called methods
Matt Ellis edited this page Oct 14, 2018
·
15 revisions
This inspection will want if the Camera.main
property is accessed in a frequently called method, such as Update
, FixedUpdate
or LateUpdate
. 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".
This inspection was first added in Rider/ReSharper 2018.2.