AssetReference but for Scenes

I am looking at migrating from a personally developed library that manages assetbundles to Addressables. One thing that I had previously supported was PropertyDrawers for strings that shows an ObjectField for the target asset, letting designers drag and drop references, and it would save both the bundle path and the asset name within the bundle, much like how the AssetReference works in Addressables. It also supported limiting the type of asset that was allowed to be assigned as well. However, there was also additional support for Scenes. As SceneAsset is a Editor only type, I had a separate property for exposing scene references, something I don’t seem to see in AssetReference. I seem to be able to select scenes in the AssetReference UI, but there’s no API that would allow loading a scene from it.

On a side note: the property drawer for AssetReference seems to be broken in v0.1.2. it uses the full property path as the label. The type and label restriction attributes don’t seem to work either. there’s also a UIElements error logged when trying to select an asset.

This works well for me:

[Serializable]
public class AssetReferenceScene
#if UNITY_EDITOR
    : AssetReferenceT<SceneAsset>
#else
    : AssetReference
#endif
{
    public AssetReferenceScene(string guid) : base(guid)
    {
    }
}
5 Likes