I work on a simple game for mobile an try to optimize it as far as possible.
Therefore I checked the Profiler an recognized, that I had a GC allocation at a SendMouseEvent.DoSendMouseEvents() of 0.6 KB.
Dont get me wrong, this is not much of a problem and the game runs fine, but I was wondering where it came from, because I ended up with deactivating all but the camera in my scene, and it still was there. If Altough if I create a new scene, I dont have any GC allocation at all (Unity 5.6).
So i tried to find the difference and ended up recognizing that I had deleted all the unused components from the camera (GUI Layer, GUI Flare Layer).
When I instead leave the GUI Layer on the camera, the problem is gone, even if it is deactivated and not deleted. Do you guys have any idea where this came from even though the GUI Layer is already marked as Legacy an not needed within the new UI System?
The GUILayer component is required / used by the old GUITexture and GUIText components. It’s used for hit detection on those components. Inside “DoSendMouseEvents” there is this code which is executed for each camera:
As you can see the code uses GetComponent to get the GUILayer component on the camera.
Your problem comes from a debugging feature that only exists inside the UnityEditor. Whenever GetComponent would return a “null” value, it actually returns an instance that pretends to be null. This is used to show a more meaningful error message in the console whenever you try using that “null” value.
This is only an overhead in the editor. At runtime (in a build) this is not a problem. See this Unity blog post for more details.