Comments (22)
Is there any news?
from play-unity-plugins.
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.
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.
Is there any update on it?
from play-unity-plugins.
any update on this feature?
from play-unity-plugins.
Hi, any updates on that? (using Play Asset Delivery with Addressables)
from play-unity-plugins.
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.
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.
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.
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.
Yes that's right.
from play-unity-plugins.
Ok thanks for reply, i will wait for update.
from play-unity-plugins.
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.
that's and amazing use of addressable.
from play-unity-plugins.
For those interesting making this a package: https://github.com/jelte/be.khepri.addressables-pad
from play-unity-plugins.
Addressable support would be great. The old asset bundels are not really supported anymore by Unity.
from play-unity-plugins.
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.
Our team is also waiting for more information on this.
from play-unity-plugins.
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!!
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.
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.
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.
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)
- Android apk release play consoleGoogle Unity installation
- Screenshot (Sep 28, 2023 7:35:21 AM)
- Downloads gets stuck from Google play side
- JNI Global Reference Overflow Bug
- Duplicate class com.google.android.play.core.common.IntentSenderForResultStarte HOT 4
- App update rejected due to error on asset pack download : Error(-13) HOT 2
- BundletoolHelper.BuildApkSet doesn't sign apks
- Google Play In-App Review API - Error posting review "Expected UNIVERSAL BIT STRING, but found UNIVERSAL SEQUENCE"
- AssetModuleException: Session not found HOT 14
- Build Problem on CI by Docker
- Pad Issue After Download HOT 1
- Unity 2022.3.14f1 requires com.google.android,play:asset.delivery version 2.1.0 HOT 3
- Asset Delivery : Bundles can't restart/continue downloading after interrupting it in notification bar HOT 11
- Issue with Google Play Games PC InputSDK Integration in Unity
- Crash MissingForegroundServiceTypeException HOT 1
- Play In-App Update Plugin needs update for Android 14 compatibility HOT 11
- Unity 2021.3.34f1 used last play asset delivery libs HOT 1
- One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts HOT 3
- Add Git tag for last release package HOT 1
- Could we have play games v2 for unity here too?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play-unity-plugins.