-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ability to provide custom a AssetIo
implementation
#1037
Conversation
It's already possible to use a custom For example, here is how I use a custom builder
.add_plugins_with(DefaultPlugins, |group| {
return group
.disable::<bevy::asset::AssetPlugin>()
.add_after::<bevy::asset::AssetPlugin, _>(asset_io::InMemoryAssetPlugin);
}); |
@mockersf thanks, that makes sense. I think their may still be some value in allowing the default asset plugin to run. Replacing the whole |
It is possible to get the existing AssetIo resource, wrap it and then insert own replacing the default one. |
@smokku This still has the problem of copying potentially changing initialization code of the From what I see, the One thing I am missing with my proposed approach is to export the ability to construct the platform default |
I think the factory approach in this pr works, but maybe its too much machinery for what we get? Is there a reason to not do something like this: struct AssetIoOverride(Box<dyn AssetIo>); That enables any plugin to override the defaults (or override overrides that came before) using arbitrary criteria (ex: platform, configuration, etc) |
I started down that road at one point, but it would require taking ownership of the It made me think that it might be nice for there to be a separate channel for initialization data that is not needed once the world is up and running. I don't know how something like that would be structured though. I suppose it could just be a set of resources that only lives until the |
I looked at taking the |
Alternatively it could be: struct AssetIoOverride(Option<Box<dyn AssetIo>>) So that the |
Alternatively: why not just let plugins insert their own AssetServer instance? AssetPlugin could just check to see if it exists before trying to create the default instance. That keeps the api small and seems like it accomplishes the desired outcomes. |
how about, in pub fn create_default_asset_io (settings: &AssetServerSettings) -> Box<dyn AssetIo>;
pub fn build_asset_server_with_io (app: &mut AppBuilder, asset_io: Box<dyn AssetIo>); and then in user code: app.add_plugins_with(DefaultPlugins, |group| {
group.disable::<bevy::asset::AssetPlugin>()
});
bevy::asset::build_asset_server_with_io (app, Box::new(CustomAssetIo)); This way the engine still handles all of the initialization, keeping user code from needing to know how to do it. And there is very little machinery, just two extra methods available. |
I still think inserting a custom AssetServer feels like the simpler solution. No new interfaces, just a single existence check in AssetPlugin. I think people understand constructors pretty well. |
That is certainly the most bang for our buck. I was just trying keep the lookup of the IO task pool out of user code, but it's not much of a savings. I will update the PR to go with this approach. |
expose method to construct and instance if the default asset IO
1d1e93d
to
6b692db
Compare
I rework this PR to use the suggested approach and added an example to demonstrate the correct way to use it. |
Looks good to me. Thanks! |
It works by allowing you to add a factory function as a resource before adding the default plugins. The factory function is given access to the
AppBuilder
instance so that it can look for any configuration it might require.