How to disable expensive method warning project-wide for Unity's Debug.Log calls?
I want to avoid adding ReSharper disabling for every call to `Debug.Log` and `Debug.LogError`. I've tried subclassing ILogHandler but it seems like the `LogFormat` and `LogException` calls aren't flagged as expensive. I've tried writing a wrapper around `Debug.Log` but then I lose linking from the Unity console.
There's a mention here: https://youtrack.jetbrains.com/issue/RIDER-26518/Expensive-method-invocation-fix-in-Unity-moves-Debug.Log-calls-to-Start that “we have plans to improve this indicators in 19.2: separate them on different groups, each group could be disabled by users, e.g: Debug.* and == are less important than GetComponent in Update, so it will be possible to disable only minor indicators.” but I'm not seeing how to do that anywhere in the Settings.
How are others handling this? Disabling these warnings for methods where we don't have access to the definition must be a fairly common use-case, no?
Please sign in to leave a comment.
Hi!
You can change the inspection severity level in File | Settings | Editor | Inspection Settings | Inspection Severity | C# or turn off the warning messages.
Hi!
Yes, I'm aware of that setting but I only want to turn off the warning for those two specific methods: `Debug.Log` and `Debug.LogError`. I still, for example, want to be warned if a method leads to other expensive calls like `GetComponent`.
Hi WongWray!
I don't think this is possible. One can suppress warning e.g. for everything inside method/class. The closest feature to your scenario is to use Disable once with comment for each `Debug.Log` or `Debug.LogError` calls.
That's unfortunate, I was hoping to not have to have those comments all over my project. I'm going to look into creating a custom logger at some point to see if that helps. Thank you for the help!
Hi WongWray!
I've dug around a little bit and found that we have the following similar feature request for Unity plugin. It is close to your case, but not exactly the same. Please upvote/comment on it to show your interest or create a new one if you think this would be better.
Have a great day!
As this is the top response on search engines right now I just wanted to weigh in with how I've personally solved this. It may not be the best solution but it solves the 2 main issues of having to wrap all logs in #if UnityEditor for performance, while also disabling the resharper warnings for log lines.