GithubHelp home page GithubHelp logo

Comments (22)

AGulev avatar AGulev commented on June 2, 2024 27

Is there any news?

from play-unity-plugins.

supersolid-jelte avatar supersolid-jelte commented on June 2, 2024 16

Actually, this was easier that I thought it would be :)

(Updated post)

Steps:

Preprocessor to remove all bundles (except catalog.bundle) from streaming assets folder

This is to not include them in the base build, they will be added via the AssetPackConfig.

public class AddressablesPlayerBuildAndroidProcessor : IPreprocessBuildWithReport
{
    public int callbackOrder => 2;
    
    public void OnPreprocessBuild(BuildReport report)
    {
        IEnumerable<string> bundles = Directory.GetFiles(Addressables.PlayerBuildDataPath)
            .Where(file => file.EndsWith(".bundle"))
            .Where(file => !file.EndsWith("catalog.bundle"))
            .ToDictionary(file => file, AssetPackBuilder.GetAssetPackGroupSchema)
            .Where(pair => pair.Value != null)
            .Select(pair => pair.Key);
        foreach (string bundle in bundles)
        {
            File.Delete(bundle);
        }
    }
}

Callback order is import as you want it happening after the addressables Preprocessor, which copies the asset bundles to the StreamingAssets folder (PlayerBuildDataPath).

Generate AssetPackConfig based on all other bundles.

This is called during our build process after the addressables have been processed.

public class AssetPackBuilder
{
     public static AssetPackConfig CreateAssetPacks()
     {
          IEnumerable<Tuple<string, AssetPackGroupSchema, string>> bundles = Directory.GetFiles(Addressables.BuildPath)
              .Where(file => file.EndsWith(".bundle") && !file.EndsWith("catalog.bundle"))
              .Select(file => new Tuple<string, AssetPackGroupSchema, string>(file, GetAssetPackGroupSchema(file), Path.GetFileNameWithoutExtension(file)))
              .Where(pair => pair.Item2 != null);
          foreach (var bundle in bundles)
          {
              assetPackConfig.AssetPacks.Add(bundle.Item3, bundle.Item2.CreateAssetPack(bundle.Item1));
          }
          return assetPackConfig;
     }

     public static AssetPackGroupSchema GetAssetPackGroupSchema(string bundle)
     {
          return AddressableAssetSettingsDefaultObject.Settings.groups
              .Where(group => group.HasSchema<AssetPackGroupSchema>())
              .Where(group => Path.GetFileName(bundle).StartsWith(group.Name))
              .Select(group => group.GetSchema<AssetPackGroupSchema>())
              .FirstOrDefault();
     }
}

the result is passed to Bundletool.BuildBundle

Add custom AssetBundleProvider to asset bundles.

Note: I'm using a very custom AssetBundle Provider, which handles delivering asset bundles synchronously after initial launch. As that is part of project I work on, I'm unable to share the entire code. But it is based on the default unity implementations.

Basic idea is that after checking if file path exists locally and before using a web request. The provider will check if the bundle is part of an asset pack. Here I do it very quickly by checking if the path starts with RuntimePath and ends with .bundle.

    internal class CustomAssetBundleResource : IAssetBundleResource
    {
...
        private void BeginOperation()
        {
...
            if (File.Exists(path))
            {
                ...
            }
            else if (TryHandleAssetPackFileAsynchronously(path))
            {
                return;
            }
            else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
...
        }

        private bool TryHandleAssetPackFileAsynchronously(string path)
        {
            if (!path.StartsWith(Addressables.RuntimePath) || !path.EndsWith(".bundle"))
            {
                return false;
            }
            string assetPackName = Path.GetFileNameWithoutExtension(path);
            playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
            playAssetPackRequest.Completed += request => OnPlayAssetPackRequestCompleted(assetPackName, request);
            return true;
        }

        private void OnPlayAssetPackRequestCompleted(string assetPackName, PlayAssetPackRequest request)
        {
            if (request.Error != AssetDeliveryErrorCode.NoError)
            {
                m_ProvideHandle.Complete(this, false, new Exception($"Error downloading error pack: {request.Error}"));
                return;
            }
            if (request.Status != AssetDeliveryStatus.Available)
            {
                m_ProvideHandle.Complete(this, false, new Exception($"Error downloading status: {request.Status}"));
                return;
            }
            var assetLocation = request.GetAssetLocation(assetPackName);
            m_RequestOperation = AssetBundle.LoadFromFileAsync(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            m_RequestOperation.completed += LocalRequestOperationCompleted;
        }
....
}

It's also possible to load the bundle from the asset pack synchronously :) (atleast for fast-install, haven't tested rest.) (note: this is a requirement for the project I work on, so it's great that it works ;))

        private bool TryHandleAssetPackFileSynchronously(string path)
        {
            if (!path.StartsWith(Addressables.RuntimePath) || !path.EndsWith(".bundle"))
            {
                return false;
            }
            string assetPackName = Path.GetFileNameWithoutExtension(path);
            playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
            Exception exception = null;
            if (playAssetPackRequest.IsDone) 
            {
                // asset pack was downloaded on initial launch of the game, so it should be done when loading it synchrounsly.
                var assetLocation = playAssetPackRequest.GetAssetLocation(assetPackName);
                m_AssetBundle = AssetBundle.LoadFromFile(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            }
            else
            {
                exception = new Exception($"Asset Pack was not retrieved asynchronously: '{assetPackName}'.");
            }
            m_ProvideHandle.Complete(this, m_AssetBundle != null, exception);
            return true;
        }

Download progress

This is currently not working because addressables still thinks of the asset bundle as being a local bundle and not a remote.
So when it computes the download size it returns 0. The data for this is generated during the building of the asset bundles, changing this would require a custom build script (copy & changing the existing default one doesn't work as it depends on a lot of internals...).

The solution to this is to call PlayAssetDelivery.GetDownloadSize for each pack that needs to be downloaded (sadly no combined call for this).

improvements

for production ready code, you'll probably will need to handle things like waiting for wifi (for large packs larger than 150MB), errors and per bundle configuration so you can specify the AssetPackDeliveryMode for each bundle (probably via adding a Schema to the Group).

    [DisplayName("Play Asset Delivery")]
    public class AssetPackGroupSchema : AddressableAssetGroupSchema
    {
        public enum AssetPackDeliveryMode
        {
            InstallTime = 1,
            FastFollow = 2,
            OnDemand = 3,
        }
        
        [SerializeField]
        AssetPackDeliveryMode deliveryMode;

        public AssetPack CreateAssetPack(string bundle)
        {
            return new AssetPack
            {
                DeliveryMode = (PlayAssetPackDeliveryMode) deliveryMode,
                AssetBundleFilePath = bundle
            };
        }
    }

note:

the current game I'm working is in no rush to add support for this as we are currently projected to be at the AAB cap in 8 to 9 months :), but it was a fun exercise and test to see if this would work.

from play-unity-plugins.

thanwah avatar thanwah commented on June 2, 2024 12

Thanks everyone who has commented on this issue and/or +1'd it. It's very helpful for us to hear from developers which new features would be the most useful.

We are currently prioritizing feature development for Q3 (July-September), and this is a good candidate to make the list. @jamcohen or I will respond back later this month with whether this made the cut for Q3.

from play-unity-plugins.

buihuuloc avatar buihuuloc commented on June 2, 2024 11

Is there any update on it?

from play-unity-plugins.

GilbertoBitt avatar GilbertoBitt commented on June 2, 2024 9

any update on this feature?

from play-unity-plugins.

AGulev avatar AGulev commented on June 2, 2024 8

Hi, any updates on that? (using Play Asset Delivery with Addressables)

from play-unity-plugins.

tutipeti avatar tutipeti commented on June 2, 2024 3

Any updates on this @thanwah or @jamcohen?
The original guesstimate of Q3 is gone for a while, it would be nice to get some feedback finally.

from play-unity-plugins.

maguslin avatar maguslin commented on June 2, 2024 3

We use unity addressable to pack game sources recently and this new "Play Asset Delivery" make us no choise . Any help could you give us ?Thank you very much!!

from play-unity-plugins.

thanwah avatar thanwah commented on June 2, 2024 2

Play Asset Delivery does not currently support Addressables, but this is something that we're looking at. I'll try to provide an update here once we know where it ends up on our roadmap.

Thank you @ehidna for creating this issue since it helps us know whether to prioritize this.

from play-unity-plugins.

thanwah avatar thanwah commented on June 2, 2024

Thanks @ehidna for the question.
To clarify, are you asking about using Play Asset Delivery with Addressables and packaging the asset packs within an AAB?

from play-unity-plugins.

ehidna avatar ehidna commented on June 2, 2024

Yes that's right.

from play-unity-plugins.

ehidna avatar ehidna commented on June 2, 2024

Ok thanks for reply, i will wait for update.

from play-unity-plugins.

efarraro avatar efarraro commented on June 2, 2024

I'm not currently using Addressables, but plan to for my next project. +1 to this. It seems that Addressables is the recommended approach moving forward, so it'd be important to have support for it.

from play-unity-plugins.

GilbertoBitt avatar GilbertoBitt commented on June 2, 2024

that's and amazing use of addressable.

from play-unity-plugins.

supersolid-jelte avatar supersolid-jelte commented on June 2, 2024

For those interesting making this a package: https://github.com/jelte/be.khepri.addressables-pad

from play-unity-plugins.

drallcom3 avatar drallcom3 commented on June 2, 2024

Addressable support would be great. The old asset bundels are not really supported anymore by Unity.

from play-unity-plugins.

s6-willard avatar s6-willard commented on June 2, 2024

Is there any update on this? Unity has been for the longest time phasing out Asset Bundles in favor of Addressables, so I'm not sure why a feature as new as Play Asset Delivery would be given an integration using only Asset Bundles (I know that Addressables are just wrappers for Asset Bundles, but the steps above do not work for all use cases). As it stands now, PAD is completely unusable for us.

from play-unity-plugins.

jonas-johansson avatar jonas-johansson commented on June 2, 2024

Our team is also waiting for more information on this.

from play-unity-plugins.

GilbertoBitt avatar GilbertoBitt commented on June 2, 2024

We use unity addressable to pack game sources recently and this new "Play Asset Delivery" make us no choise . Any help could you give us ?Thank you very much!!

https://developer.android.com/guide/playcore/asset-delivery/integrate-unity#configure-asset-packs-api

there's a documentation about it on integrate but just for asset bundle not for the addresables system itself.. maybe do a custom process just for that similar to what we do to add this integration on playfab.

from play-unity-plugins.

minidragon-jacky avatar minidragon-jacky commented on June 2, 2024

For those interesting making this a package: https://github.com/jelte/be.khepri.addressables-pad

I just try to use this package but error comes out. Hope the developer still working on it.

from play-unity-plugins.

IgorTime avatar IgorTime commented on June 2, 2024

Any news? We gets close to the Soft Launch with our game, but this feature is blocking us, and we have to write our own solution which stopping us for months.

from play-unity-plugins.

thanh-nguyen-kim avatar thanh-nguyen-kim commented on June 2, 2024

Here is my tutorial using @supersolid-jelte solution with a little modified on his plugin and a working example. Hope it will help.

https://killertee.wordpress.com/2021/09/04/unity-play-asset-delivery-and-addressable-assets/

from play-unity-plugins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.