-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(read_console): force console severity flags ON to bypass UI filter (silent 0 entries) #1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: beta
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Map the file structure first, then inspect the relevant region.
ast-grep outline MCPForUnity/Editor/Tools/ReadConsole.cs --view expanded || true
echo
echo "---- relevant lines ----"
sed -n '120,190p' MCPForUnity/Editor/Tools/ReadConsole.csRepository: CoplayDev/unity-mcp Length of output: 5025 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '190,330p' MCPForUnity/Editor/Tools/ReadConsole.csRepository: CoplayDev/unity-mcp Length of output: 6822 Don’t gate 🤖 Prompt for AI Agents |
||
| ) | ||
| { | ||
| // 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 12739
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 197
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 927
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 241
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 197
🌐 Web query:
Unity Editor LogEntries GetFilteringText SetFilteringText API💡 Result:
The GetFilteringText and SetFilteringText methods are internal API methods belonging to the UnityEditor.LogEntries class [1][2]. Because these methods are internal and not part of the public Unity Scripting API, they are not intended for use in production code and their signatures or functionality can change without warning [1][3]. These methods are primarily used by Unity's own Editor code—specifically the Console Window—to manage the text filter string currently applied to the console's log entries [2][4]. Key characteristics include: - Purpose: They control the search filter string used to narrow down which log entries are displayed in the Unity Editor Console [2]. - Access: As internal methods, they cannot be accessed directly via standard code references. Developers who require this functionality often use C# reflection to access the UnityEditor.LogEntries class at runtime [5][6]. - Usage in Unity's Source: The Unity ConsoleWindow class invokes GetFilteringText to retrieve the current filter state and SetFilteringText to update the filter when a user types into the Console's search field [2]. Because they are not documented public APIs, using them via reflection is considered an unstable practice for Unity development [7][5]. Developers looking to interact with the Console should be aware that these internal calls may fail if Unity changes its internal architecture in future versions [8].
Citations:
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 10298
Keep the Console mutations in cleanup.
SetFilteringText("")runs before thetry, so a throw there skips restoringconsoleFlags; when it succeeds, the search text also stays cleared. Save/restore the filter text whenGetFilteringTextis available, and move both mutations under the samefinally.🤖 Prompt for AI Agents