bevyengine / bevyengine/bevy

Add `Path` checking to `AssetReader` and/or `AssetServer`

Open
#15,671 3 comments 1 reaction 0 assignees View on GitHub
A-Assets C-Feature D-Modest S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

As described in Issue #14427, it would be nice to be able to determine if an `AssetPath` actually exists, without loading the Asset and seeing if it fails.

## What solution would you like?

The functionality should probably be added as a method on `AssetServer`. The `AssetServer` would query the corresponding Asset Source, which would ask it's `AssetReader` to determine if the `AssetPath` points to an existing file.

One way to accomplish this is to add a method onto the `AssetReader` trait which returns whether a `Path` can be read. The downside is that this would be a breaking change, and would require care to correctly implement the method on the current `AssetReader`s.

## What alternative(s) have you considered?

One alternative that doesn't require altering `AssetReader`, is to use the `AssetRead::read` method. Since this method would return an `Error` if the `Path` does not exist, we could use it to determine the existence of a `Path`. This would work perfectly for a `FileAssetReader`, which simply calls `File::open`. However some implementations, such as `AndroidAssetReader` and `HttpWasmAssetReader` load the entire asset into memory in the read method which is not ideal.

Another hacky alternative is to use the `AssetReader::is_directory` method, which commonly returns an `Error` when the `Path` does not exist. This would work for both `FileAssetReader` and `AndroidAssetReader`, but would not work (and log an error message) for `HttpWasmAssetReader`. The behavior of returning an `Error` when the `Path` doesn't exist is also not explicit, and entirely coincidental.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.