Fix Memory Profiler snapshot actions on Unity 6#1125
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMemorySnapshotOps 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. ChangesMemoryProfiler API Compatibility
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Description
Fixes Memory Profiler MCP snapshot actions on Unity 6, where
MemoryProfiler.TakeSnapshotis exposed fromUnityEngine.CoreModulewithCaptureFlagsoverloads instead of the olderUnity.MemoryProfiler.Editorreflection path.This resolves cases where
com.unity.memoryprofileris 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
MemoryProfilerfrom Unity 6/CoreModule API paths before falling back to the legacy editor assembly path.TakeSnapshotoverloads that useCaptureFlags.CaptureFlagsoverloads and legacyuintoverloads cannot be mixed.memory_list_snapshotsandmemory_compare_snapshotsto run without MemoryProfiler type discovery, since they only read.snapfile metadata.Testing/Screenshots/Recordings
uv run --extra dev pytest tests/test_manage_profiler.py -vcom.unity.memoryprofilerinstalled:memory_take_snapshotmemory_list_snapshotsmemory_compare_snapshotsprofiler_statusget_frame_timingget_countersframe_debugger_get_eventsUnity.Profiling.Memory.MemoryProfilerTakeSnapshot(string, Action<string, bool>, CaptureFlags)TakeSnapshot(string, Action<string, bool>, Action<string, bool, DebugScreenCapture>, CaptureFlags)Documentation Updates
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