docs.unity3d.com
    Show / Hide Table of Contents

    Snapshots concepts

    A memory snapshot is a record of how the memory in your application is organized at the point in a frame when the snapshot was taken.

    You can take multiple snapshots during an application's execution but this isn't the same as constant monitoring. If you need to profile how memory use in your application changes in real-time during execution, use the Memory Profiler module in the built-in Profiler.

    Define snapshot metadata

    When you capture a snapshot, you can generate MetaData on the Player side. If the Player was built from a Project that has the Memory Profiler package installed, the Player generates some default metadata for the snapshot.

    The default metadata consists of:

    • MetaData.content: Contains the Project's name, and the scripting version when you capture the Editor.
    • MetaData.platform: Contains the RuntimePlatform of the Player or the Editor that you captured, and stores it as a string.
    • MetaData.screenshot: A screenshot the Memory Profiler takes at the moment of the capture. Its size is under 480x240 pixels.

    When you capture a snapshot, you should define some metadata on the Player side so you can get a good overview of the content of your snapshot. There are two ways to do so:

    • When you don't have the Memory Profiler package in your Project, but want to add metadata to your snapshots, register a listener to MemoryProfiler.createMetaData.
    • If you have the package in your Project, keep the default data or write a metadata collector. For more information see Add Player hook below.

    Add Player hook

    To define custom metadata in a Project that has the Memory Profiler package installed, create a class that inherits from Unity.MemoryProfiler.MetadataCollect.

    You need to implement void CollectMetadata(MetaData data) in which you fill data with the information you want. You can create multiple classes that inherit from Unity.MemoryProfiler.MetadataCollect but their CollectMetadata methods have no defined call order.

    If you have a class that inherits from Unity.MemoryProfiler.MetadataCollect, it does not generate the default metadata described in Define snapshot metadata. If you want to keep some or all of the default metadata, go to the file com.unity.memoryprofiler/Runtime/MetadataInjector.cs and copy the content you want to keep from DefaultCollect(MetaData data) into your implementation.

    Ignore snapshot files in source control

    Add the .snap extension to your version control system’s ignore file to avoid committing memory snapshot files to your repository. Memory snapshot files might use large amounts of disk space.

    Back to top
    Copyright © 2023 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on Saturday, October 21, 2023