VedalAI / neuro-amongus

Among Us Plugin for Neuro-sama
GNU General Public License v3.0
531 stars 50 forks source link

Cache Camera.main #55

Closed EBro912 closed 1 year ago

EBro912 commented 1 year ago

This PR caches Camera.main within the NeuroUtilities class.

As you probably know, Unity's Camera.main calls FindGameObjectsWithTag("MainCamera") internally and does not cache it, which causes small but unnecessary CPU overhead, especially when called frequently This was improved drastically as of 2020.2, but still is almost the same as calling GetComponent. Currently, the project calls this upwards of 180 times in Visibility.IsVisible and every frame when the fake Cursor is on screen. While not very noticeable framewise, caching the main camera is recommended by Unity themselves and again relieves slight CPU overhead.