• Manual
  • API Documentation
  • Guides
  • Saving and Loading Assets

    Show / Hide Table of Contents
    • Introduction
    • Installation
    • Getting Started
    • Demos
    • The Save System API
    • Auto Save
    • Platforms
    • Security
    • Serialization
    • Supported Data Types
    • Migration
    • FAQ
    • Changelog
    • Extend
      • Overview
      • Converter
      • Encryption
      • Storage
    • Guides
      • Overview
      • Configuring Settings
      • Using Auto Save
      • Basic Saving and Loading
      • Saving and Loading Raw Data
      • Deleting the Data
      • Saving and Loading Images
      • Saving and Loading Scene Objects
      • Saving and Loading Assets
      • Saving and Loading Readonly Properties
    • Integrations
      • Overview
      • Google Play Games
      • Xbox Live
      • Bolt
      • Firebase
      • PlayFab
      • PlayMaker
      • Steam Auto-Cloud
      • Steamworks .NET
      • Facepunch Steamworks
      • Text Mesh Pro
    • Storage
      • Overview
      • Backup
      • Catalog
      • Meta Data
      • Built-in Storages
        • File
        • PlayerPrefs
        • Memory
      • Third-party Storages
        • Firebase
          • Realtime Database
          • Cloud Storage
          • Firestore
        • PlayFab
          • Entity Objects
          • Entity Files
          • User Data
        • Steam
          • Steamworks .NET
          • Facepunch Steamworks
        • Google Play
          • Saved Game
        • Xbox Live
          • Connected Storage

    Saving and Loading Assets

    Using the AssetReferenceResolver you can easily save and load assets such as Materials, Textures or any other persistent Unity object by reference instead of serializing their values completely.

    Asset Reference Resolver Component

    • Collect Project Dependencies: Collects the asset references from the scenes in the Build settings.
    • Collect Active Scene Dependencies: Collects the current active scene asset references.
    • Collect Default Dependencies: Collects all the default Unity assets references such as built-in resources, textures, materials, ...
    • Collect All Project Dependencies: Collects whole project assets references, use it at your own risk because it references all project assets which might increase the build size by reference unused assets too and take more memory and reduce performance.

    The MaterialPropertiesResolver holds a list of each material properties for easier runtime modification which is required for saving and loading Material properties at runtime.

    Material Properties Resolver Component

    You can also use the Window > Bayat > Core > Asset Reference Manager window for managing the asset references:

    Asset Reference Resolver Window

    Getting Started

    The Asset Reference Resolver is available in the project by default and is limited to only 1 instance for the whole project, so you wouldn't have to create or do anything to set it up.

    So you can easily use the Asset Reference Resolver API for saving and loading, the below code gets the GUID for the current GameObject Material if it is referenced by the Asset Reference Resolver, otherwise returns null:

    string guid = AssetReferenceResolver.Current.ResolveGuid(GetComponent<Renderer>().sharedMaterial);
    
    Object obj = AssetReferenceResolver.Current.ResolveReference(myGuid);
    

    ScriptableObjects

    In order to serialize the ScriptableObjects data, you need to enable the Serialize Scriptable Objects option on the Json Serializer Settings, otherwise they will be serialized as a reference only same as other asset types.

    • Improve this Doc
    • 0 Comments
    In This Article
    • Getting Started
    • ScriptableObjects