Major Performance Issues (EventSystem.Update())

Hello!

I’m currently working on a top-down game in Unity, and was running into an issue with performance when I have, say, 75-100 enemies on the screen (in the actual game this will never happen, however this is still an issue with performance i’d like to fix). I took a glance at the profiler, and this was the major issue:

Now, I glanced in my code, and I am doing no raycasts . My enemies (which appear to cause the issue) don’t call Camera.Main (which I had thought might be the issue, because of the Camera.get_main() being at the root of the issue).

Does anyone have any ideas as to what could be causing this? Thanks!

The tree hierarchy shows the calls, so the raycasts happen in EventSystem.RaycastAll and it’s GraphicRaycaster.eventCamera which calls Camera.main. No need to check for those in your code.

Did you make your enemies with the UI system? Do they have a graphic component (Image for example) with “raycast target” enabled? I mean, it seems they are part of the UI and marked as targetable, so the EventSystem checks whether the clicks/touches are hitting any of them.

If so, you could try disabling “raycast target” or take them out of the UI (render them with SpriteRenderer or MeshRenderer instead).

I had a similar problem and Mikael’s suggestion helped me out. Turns out I had several canvas objects with “raycast target” enabled that didn’t need it to be. Things like texts, masks, etc.