docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Set up and run the sample

    The Runtime Serialization sample shows how to save and load the full state of behavior agents at runtime.

    Use this section to do the following:

    • Import the sample
    • Explore its contents
    • Run the scene
    • Test serialization by demonstrating how agent positions and their behavior graph states are preserved across play sessions

    Import and open the sample scene

    To use the Runtime Serialization sample, follow these steps:

    1. Open the Package Manager window.
    2. Select In Project > Behavior > Samples.
    3. Select Import next to the Runtime Serialization sample.
    4. To locate the sample components, go to Project > Assets> Sample > Behavior > [version-number] > Runtime Serialization.

    The Runtime Serialization folder contains the following components:

    Component Name
    Scene Serialization.unity
    Behavior graph Agent.graph
    Prefabs Agent and Weapon
    Materials Two materials for visuals
    Scripts * SerializationExampleSceneController.cs
    * ChooseTargetPosition.cs
    * GameObjectResolver.cs (embedded example)

    Run the sample

    The Runtime Serialization sample shows how to save and restore agent state at runtime.

    To run the Serialization.unity scene, follow these steps:

    1. Double-click the Serialization.unity scene to open it.

    2. Enter Play mode.

      The scene shows 15 capsule agents that move around wielding swords.

    3. Select Save to serialize the current state of all the agents.

    4. Select Load to restore that state at any time, even after you exit and re-enter Play mode.

    Runtime serialization restores the agent positions and saves the full state of each agent's behavior graph. When you reload the graph, the agents resume their behavior from the exact point they left off.

    Additional resources

    • How behavior graph works
    • Scripts and serialization architecture
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)