How do you eliminate "OnGUI function detected on MonoBehaviour, but not called, because IMGUI module is stripped."

In the log for my dedicated server builds, I see the message “OnGUI function detected on MonoBehaviour, but not called, because IMGUI module is stripped.” I believe I know which scripts are to blame, but they’re in a third party package and I don’t want to modify them. Is there a way to keep IMGUI from being stripped?

Alternatively, is there a way suppress or hide these messages? They’re effectively spamming the log. The information isn’t useful and it clutters the log.

I figured it out. I wrote a script to locate all MonoBehaviours containing OnGui but not containing UNITY_EDITOR. There were quite a few in the Mirror package. However, they were wrapped in “#if DEBUG… #endif” I turned off “Development Build” in the profile and the messages went away.

Here’s the script. Place it under an Editor directory…

using System.IO;
using UnityEditor;
using UnityEngine;

namespace PrettyGoodSoftware
{
    public class FindOnGUIScripts : EditorWindow
    {
        [MenuItem("Custom/Find OnGUI Scripts")]
        static void Find()
        {
            var scriptPaths = Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories);

            foreach (var path in scriptPaths)
            {
                // Normalize path and check if it contains "Editor" (case-insensitive)
                string normalizedPath = path.Replace('\\', '/'); // Ensure consistency across OS
                if (normalizedPath.Contains("/Editor/")) continue; // Skip scripts in Editor folders

                var scriptContent = File.ReadAllText(path);
                if (scriptContent.Contains("OnGUI(") && !scriptContent.Contains("UNITY_EDITOR"))
                {
                    Debug.Log($"Suspect OnGUI() found in: {Path.GetFileName(path)} at {path}");
                }
            }

            Debug.Log("Search completed.");
        }
    }
}