diff --git a/MCPForUnity/Editor/Tools/ReadConsole.cs b/MCPForUnity/Editor/Tools/ReadConsole.cs index 155484b6f..c742be4f1 100644 --- a/MCPForUnity/Editor/Tools/ReadConsole.cs +++ b/MCPForUnity/Editor/Tools/ReadConsole.cs @@ -30,6 +30,8 @@ public static class ReadConsole private static FieldInfo _messageField; private static FieldInfo _fileField; private static FieldInfo _lineField; + private static PropertyInfo _consoleFlagsProperty; + private static MethodInfo _setFilteringTextMethod; // Static constructor for reflection setup static ReadConsole() @@ -99,6 +101,17 @@ static ReadConsole() if (_lineField == null) throw new Exception("Failed to reflect LogEntry.line"); + // Reflect consoleFlags property to save/restore severity toggles + _consoleFlagsProperty = logEntriesType.GetProperty( + "consoleFlags", + staticFlags + ); + // Reflect SetFilteringText to clear/restore the console search filter + _setFilteringTextMethod = logEntriesType.GetMethod( + "SetFilteringText", + staticFlags + ); + // (Calibration removed) } @@ -133,6 +146,7 @@ public static object HandleCommand(JObject @params) || _messageField == null || _fileField == null || _lineField == null + || _consoleFlagsProperty == null ) { // Log the error here as well for easier debugging in Unity Console @@ -246,6 +260,25 @@ bool includeStacktrace int resolvedCursor = Mathf.Max(0, cursor ?? 0); int pageEndExclusive = resolvedCursor + resolvedPageSize; + // Save and override console severity toggles so that StartGettingEntries + // returns all entries regardless of the Console window's UI filter state. + // Unity's internal LogEntries.StartGettingEntries() respects these flags + // and silently returns 0 when a toggle is off. + int savedConsoleFlags = (int)_consoleFlagsProperty.GetValue(null); + int forcedFlags = savedConsoleFlags + | (1 << 7) // LogLevelLog + | (1 << 8) // LogLevelWarning + | (1 << 9); // LogLevelError + _consoleFlagsProperty.SetValue(null, forcedFlags); + + // Also clear the console search filter to avoid text-based filtering + // at the source; the tool applies its own filterText parameter later. + // GetFilteringText may not exist, so we clear without saving. + if (_setFilteringTextMethod != null) + { + _setFilteringTextMethod.Invoke(null, new object[] { string.Empty }); + } + try { // LogEntries requires calling Start/Stop around GetEntries/GetEntryInternal. @@ -392,6 +425,15 @@ bool includeStacktrace McpLog.Error($"[ReadConsole] Failed to call EndGettingEntries: {e}"); // Don't return error here as we might have valid data, but log it. } + // Restore the original console severity toggles + try + { + _consoleFlagsProperty.SetValue(null, savedConsoleFlags); + } + catch (Exception e) + { + McpLog.Error($"[ReadConsole] Failed to restore console flags: {e}"); + } } if (usePaging)