Skip to content

Fix Memory Profiler snapshot actions on Unity 6#1125

Open
DLSinnocence wants to merge 2 commits into
CoplayDev:betafrom
DLSinnocence:fix/memory-profiler-coremodule-api
Open

Fix Memory Profiler snapshot actions on Unity 6#1125
DLSinnocence wants to merge 2 commits into
CoplayDev:betafrom
DLSinnocence:fix/memory-profiler-coremodule-api

Conversation

@DLSinnocence
Copy link
Copy Markdown

@DLSinnocence DLSinnocence commented May 14, 2026

Description

Fixes Memory Profiler MCP snapshot actions on Unity 6, where MemoryProfiler.TakeSnapshot is exposed from UnityEngine.CoreModule with CaptureFlags overloads instead of the older Unity.MemoryProfiler.Editor reflection path.

This resolves cases where com.unity.memoryprofiler is installed, but MCP still returns “Package com.unity.memoryprofiler is required.”

Type of Change

Bug fix (non-breaking change that fixes an issue)

Changes Made

  • Resolve MemoryProfiler from Unity 6/CoreModule API paths before falling back to the legacy editor assembly path.
  • Support TakeSnapshot overloads that use CaptureFlags.
  • Keep legacy overload fallbacks for older Unity versions.
  • Verify the selected overload parameter type before invoking it, so Unity 6 CaptureFlags overloads and legacy uint overloads cannot be mixed.
  • Allow memory_list_snapshots and memory_compare_snapshots to run without MemoryProfiler type discovery, since they only read .snap file metadata.

Testing/Screenshots/Recordings

  • Ran uv run --extra dev pytest tests/test_manage_profiler.py -v
    • Result: 40 passed
  • Verified in a Unity 6 project with com.unity.memoryprofiler installed:
    • memory_take_snapshot
    • memory_list_snapshots
    • memory_compare_snapshots
    • profiler_status
    • get_frame_timing
    • get_counters
    • frame_debugger_get_events
  • Verified error paths for missing snapshot files and missing compare parameters.
  • Verified Unity 6 reflection exposes:
    • Unity.Profiling.Memory.MemoryProfiler
    • TakeSnapshot(string, Action<string, bool>, CaptureFlags)
    • TakeSnapshot(string, Action<string, bool>, Action<string, bool, DebugScreenCapture>, CaptureFlags)

Documentation Updates

  • I have added/removed/modified tools or resources

Related Issues

Additional Notes

The Memory Profiler list and compare actions only operate on snapshot file metadata, so they should not fail just because runtime MemoryProfiler type discovery fails.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced memory profiler detection to support additional Unity versions and configuration variants
    • Improved memory snapshot capture to work seamlessly with various Unity API implementations
    • Refined snapshot operations to handle edge cases more reliably across different system configurations

Review Change Stack

DLSINNOCENCE added 2 commits May 14, 2026 17:01
Unity 6 exposes MemoryProfiler.TakeSnapshot from UnityEngine.CoreModule with CaptureFlags overloads, so the old Unity.MemoryProfiler.Editor reflection path makes memory_take_snapshot report that com.unity.memoryprofiler is missing even when the package is installed. The profiler list and compare actions only inspect snapshot files, so they no longer depend on MemoryProfiler type discovery.

Constraint: Unity 6 moved MemoryProfiler APIs into UnityEngine.CoreModule.

Rejected: Require com.unity.memoryprofiler editor assembly type discovery for all memory actions | list and compare only need filesystem metadata.

Confidence: high

Scope-risk: narrow

Tested: uv run --extra dev pytest tests/test_manage_profiler.py -v

Tested: Reflected Unity 6 MemoryProfiler.TakeSnapshot overloads in GameClient editor.

Not-tested: Full Unity package test suite.
The MemoryProfiler reflection code now verifies the selected overload's trailing parameter type before invoking it. This keeps Unity 6 CaptureFlags overloads and legacy uint overloads from being mixed in environments where both type families can be discovered.

Constraint: Reflection overload selection spans Unity versions with different trailing argument types.

Confidence: high

Scope-risk: narrow

Tested: Patched GameClient PackageCache and verified memory_take_snapshot, memory_list_snapshots, memory_compare_snapshots.

Tested: Verified profiler_status, get_frame_timing, get_counters, frame_debugger_get_events, and compare error paths.

Not-tested: Full Unity package test suite.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e0c635d-e684-490d-8b90-0b69cbce2f60

📥 Commits

Reviewing files that changed from the base of the PR and between a2a5edf and d9431c5.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Tools/Profiler/Operations/MemorySnapshotOps.cs

📝 Walkthrough

Walkthrough

MemorySnapshotOps extends type detection across Unity's MemoryProfiler stable, experimental, and legacy namespaces. TakeSnapshotAsync now conditionally discovers and invokes multiple method overloads based on available types. ListSnapshots and CompareSnapshots remove early package-presence guards to allow snapshot file operations independent of package installation.

Changes

MemoryProfiler API Compatibility

Layer / File(s) Summary
Type variant detection
MCPForUnity/Editor/Tools/Profiler/Operations/MemorySnapshotOps.cs
MemoryProfilerType lookup now tries stable Unity.Profiling.Memory.MemoryProfiler and experimental UnityEngine.Profiling.Memory.Experimental.MemoryProfiler before falling back to the legacy Unity.MemoryProfiler.MemoryProfiler.
TakeSnapshot overload discovery and invocation
MCPForUnity/Editor/Tools/Profiler/Operations/MemorySnapshotOps.cs
Overload resolution detects DebugScreenCapture and CaptureFlags types from both namespaces, conditionally attempts 4-parameter, 2-parameter, and simple signatures based on type availability, and refines reflection invocation to distinguish overloads by parameter count and type (supporting both strongly-typed CaptureFlags and legacy uint forms).
Snapshot file operations
MCPForUnity/Editor/Tools/Profiler/Operations/MemorySnapshotOps.cs
ListSnapshots and CompareSnapshots remove early HasPackage guards, allowing filesystem enumeration and file metadata comparison to proceed without requiring the memory profiler package to be installed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Through namespaces I hop with care,
Each API variant found with flair,
Four parameters, two, or just one more,
Snapshots dance where guardians were before!
Files listed free, no packages required—
Unity's profiler dreams, now inspired!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing Memory Profiler snapshot actions specifically for Unity 6 compatibility.
Description check ✅ Passed The description is comprehensive, including all required template sections: clear description of the bug, type of change, specific changes made, testing performed, and related context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant