docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Use case: Load a Model From StreamingAssets

    This use case outlines the basics of setting up a streaming-ready scene. Use this use case to learn how to stream a model from the project StreamingAssets directory.

    To accomplish this use case, do the following:

    1. Save a model in the StreamingAssets directory.
    2. Create an offline streaming behavior.
    3. Set up a new scene.

    How do I...?

    Save a model in the StreamingAssets directory

    Copy a data-streaming model1 into the StreamingAssets directory and name your copied directory MyModel. Make sure the tileset.json file is inside the MyModel directory.

    Create an offline streaming behavior

    To create a offline streaming behavior, follow these steps:

    1. Open your Unity project.
    2. In the Project window, select and hold the Assets folder .
    3. Select Create > C# Script.
    4. Rename the new script as OfflineDataStreaming.
    5. Open the OfflineDataStreaming script and replace the content with the following:
      using System;
      using System.IO;
      using Unity.Cloud.DataStreaming.Runtime;
      using UnityEngine;
      
      public class OfflineDataStreaming : MonoBehaviour
      {
          [SerializeField]
          Camera m_Camera;
      
          [SerializeField]
          string m_Path;
      
          [SerializeField]
          float m_ScreenSpaceError = StageObserverFactory.DefaultScreenSpaceError;
      
          IDataStreamer m_Streamer;
      
          void Start()
          {
              // Create the settings for our streamer.
              var builder = DataStreamerSettingsBuilder.CreateDefaultBuilder();
      
              var uri = new Uri(
                  new Uri($"{Application.streamingAssetsPath}{Path.DirectorySeparatorChar}"),
                  m_Path);
      
              var settings = builder.Build();
      
              // Start to stream.
              m_Streamer = IDataStreamer.Create();
      
              var observer = StageObserverFactory.CreateCameraObserver(
                  m_Camera,
                  m_ScreenSpaceError);
      
              var stage = m_Streamer.Open(settings);
              stage.Observers.Add(observer);
              stage.Models.Add(x => x.FromUri(uri));
          }
      
          void OnDestroy()
          {
              m_Streamer?.Close();
          }
      }
      

    Set up a new scene

    To set up a new scene, follow these steps:

    1. Create a new scene.

    2. Create a GameObject called Streamer.

    3. In the Inspector window, select Add Component.

    4. Add the Offline Data Streaming component.

    5. In the Path inspector field, write MyModel/tileset.json.

      Screenshot of the Offline Data Streaming MonoBehaviour

    6. Add a Camera in your scene if one doesn't exist.

    7. Set the OfflineDataStreaming component Camera value to your scene camera.

    8. Select Play to view your model load in front of the camera.2


    1To generate a model from the Asset Manager, refer to the Use case: Generate an offline dataset

    2 If the model does not load in front of the camera, select the menu item Edit / Frame Streamed Model to frame the model in the Unity Scene View.

    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)