Skip to content

Brian-Jiang/SmartReference

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Smart Reference

version 0.9.0

Summary

Smart Reference is a Unity plugin that allows you to lazy load references to other objects in ScriptableObject and MonoBehaviour. You may be familiar to use ScriptableObject store data, but when you reference other objects, they will be treated as dependencies and will be loaded when the ScriptableObject is loaded. This could be slow if you have a lot of references. For details, see this article.
Smart Reference allows you to load references only when you need them at runtime with same workflow in editor.

Quick Start

  1. Use SmartReference instead of Object. See how they look exactly same in the inspector.

        public class MonsterData : ScriptableObject {
            public SmartReference<GameObject> prefab;
            public SmartReference<Sprite> icon;
            public string description;
        }
  2. Initialize smart reference when your game start

    • If you use Unity Addressables, you need to add USE_UNITY_ADDRESSABLES symbol to your player settings, then call
      SmartReference.Runtime.SmartReference.InitWithAddressablesLoader();
    • If you use your own custom loader, call
      SmartReference.Runtime.SmartReference.Init((path, type) => {
          return MyLoadFunction.Load(path, type);
      }, (path, type, callback) => {
          MyLoadFunction.LoadAsync(path, type, obj => {
              callback(obj);
          });
      });
      or
      var loader = new CustomLoader {
          loader = MyLoadFunction,
          loaderAsync = MyAsyncLoadFunction,
      };
      SmartReference.Runtime.SmartReference.Init(loader);
    • If you use Unity Resources(not recommended, see why), call
      SmartReference.Runtime.SmartReference.InitWithResourcesLoader();
  3. SmartReference will automatically update paths before player build in case you move or rename the referenced asset. If you want to manually update all references in the project, go to Tools/SmartReference/Update All References to update all references in the project.

Supports

If you have any questions, please leave an issue at GitHub. Thank you for your support!

About

Smart Reference is a Unity plugin that allows you to lazy load references to other objects in ScriptableObject and MonoBehaviour.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages