We are working on a game where the user can add objects to a scene and will need to be able to save the scene and load it later. The Addressables system initially sounded like a great solution; this is what I envisioned:
- We add prefabs to the Addressables system
- The player adds objects (instantiated from those prefabs) to a scene.
- When the player saves, we serialize each object’s Addressables address, position and rotation, etc.
- When the player loads, we deserialize the data. For each object, we instantiate from the corresponding prefab using the Addressables address, then apply the position, rotation, etc.
The problem is that it seems very difficult (impossible?) to actually retrieve an Addressable’s address at runtime.
If we do [SerializeField] private GameObject prefab;
, we don’t know anything about whether the prefab asset is included in the Addressables system:
If we load assets from Addressables using a label Addressables.LoadAssetsAsync<T>(label, null).Completed += OnAssetsLoaded;
, we also don’t get any information about the assets’ addresses.
We can use AssetReferenceGameObject (which is very frustrating to use due to the clunky dropdown in the inspector), but that still doesn’t expose the asset’s address. AssetReference does have a “RuntimeKey” property but the documentation is not very clear on how this actually works. If we serialize the RuntimeKey into a save file, is it going to be valid the next time the player runs the game? Does the RuntimeKey change when we make a new build?