Scene LoadAsync with custom AssetBundleProvider not working

I have a custom AssetBundleProvider that need to rewrite the URL, since the CDN (PlayFab) generate a temporary URL for download.

public class PlayFabStorageAssetBundleProvider : AssetBundleProvider
{
    private string newUrl = "";
    public override void Provide(ProvideHandle provideHandle)
    {
        //        var addressableId = provideHandle.Location.InternalId.Replace("playfab://", "");
        var addressableId = provideHandle.Location.InternalId.Replace(Launcher.buildPath, "");

        //        GetContentDownloadUrlRequest dRequest = new GetContentDownloadUrlRequest() { Key = addressableId, ThruCDN = false };
        PlayFabClientAPI.GetContentDownloadUrl(new GetContentDownloadUrlRequest() { Key = addressableId, ThruCDN = false },
            result =>
            {
                newUrl = result.URL;
                provideHandle.ResourceManager.InternalIdTransformFunc = TransformFunc;
                provideHandle.ResourceManager.TransformInternalId(provideHandle.Location);
                base.Provide(provideHandle);
            },
            error => Debug.LogError(error.GenerateErrorReport()));
    }

    private string TransformFunc(IResourceLocation location)
    {
        return location.InternalId.Replace(location.InternalId, newUrl);
    }
}

Since InternalID is readonly, I use the suggested method of TransformFunc.

That work well… However when the data is downloaded and the scene ready to load the InternalLoadScene function do

            internal SceneInstance InternalLoadScene(IResourceLocation location, bool loadingFromBundle, LoadSceneMode loadMode, bool activateOnLoad, int priority)
            {
//                var internalId = m_ResourceManager.TransformInternalId(location);// That won't work since we modify the location
                var internalId = location.InternalId;
                var op = InternalLoad(internalId, loadingFromBundle, loadMode);
                op.allowSceneActivation = activateOnLoad;
                op.priority = priority;
                return new SceneInstance() { m_Operation = op, Scene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1) };
            }

The commented line being the original one. So it call the TransformInternalID, who then return the “fixed” URL while the SceneLoad expect the scene Name.

I tried to change my TransformFunc to be

    private string TransformFunc(IResourceLocation location)
    {
        if (location.InternalId.StartsWith(Launcher.buildPath))
            return location.InternalId.Replace(location.InternalId, newUrl);
        else
            return location.InternalId;
    }

So returning the untransform InternalID, if the current ID is not a URL path.
While that work, it cause a new issue, it break caching for the SCENE bundle.

So not sure what is the solution, but either:

  1. SceneLoad should get the internalID directly
  2. TransformFunc should have a way to identify if it’s a load/cache/scene name call
  3. Caching should look at both the internalID and transform one?
  4. Anything else that someone see as a better solution

Hey again @Morphus74 .

I’ll check with the team, I think someone is already investigating this but I’m not sure. If not, I’ll dig around and give you an update as soon as possible.

Thanks for providing a detailed explanation of your problem by the way. This helps.

1 Like

Just to give you an update : an internal ticket has been created for this. Someone from the team will investigate and update this thread as soon as possible.

Thank you