Basically I have a lot of GetComponent<…>() functions in my code. Which are fine and don’t slow my game down at all once built despite what people say.
The only problem is in the editor the profiler always seems to think these GetComponent functions take up lots of milliseconds.
So basically I want to somehow make the profiler ignore these functions. Or alternatively stop GetComponent from generating garbage.
(Apparently GetComponent generates error strings which can be caught but generally just get garbage collected in the editor).
They’re not generating errors. Apparently they just generate some kind of debugging information that slows everything down in the editor. Because the information has to be garbage collected. That’s what I read.
You should profile in the build, not the editor. That way any Unity editor specific implementation stuff will be pulled out.
The profiler isn’t lying too you. You really should listen to it (assuming you are doing it in a build and not in editor). If it tells you GetComponent is taking up most of your frame time, then you probably want to optimise calls to GetComponent.
If GetCopmonent isn’t taking up that much time, and the profiler still lists it as taking the most time, then chances are there is nothing to optimise.
In other words, why are you bothering to profile of if you aren’t interested in what the profiler has to say.
How do you profile in the build? I’ve never been able to work it out. Can I profile a build of a Windows Standalone application? I can’t find any instructions for it.
When you go to build you need to click on Debug Build and Auto Attach Profiler. The three check boxes on the right under where you add scenes to the build.
You can enable deep profiling in a windows standalone version of the build by opening up a command line window into the folder where you game is located and running
gamename.exe -deepprofiling
If it is properly setup to attach to the profiler, it will now do so in deep profiling mode.
In 2019.3 you can build Player with the DeepProfiling support from BuildWindow and with BuildPlayer API.
Both Mono and Il2CPP scripting backends are now supported.