bevyengine / bevyengine/bevy

Provide an API for getting the full path of a file loaded by the `FileAssetReader`

Open
#19,695 2 comments 1 reaction 0 assignees View on GitHub
A-Assets A-Editor C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

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

I use BRP to recreate parts of the client app in the server. The client app may load arbitrary glTFs, and I want to load them as well. This is not a security concern or anything, the end-user uses the BRP-server program on their own machine for their own client.

So, I need to know the path for where to load the assets from. For the moment, I'm fine with just loading plain old files from disk. No Wasm support, no android support, no processed files, just plain old models stored in the assets dir.

But how do I get there? Well, the best way I have found is
- Use [`FileAssetReader::get_base_path`](https://docs.rs/bevy/latest/bevy/asset/io/file/struct.FileAssetReader.html#method.get_base_path) to get the base path, like `/home/hohenheim/games/grand-theft-bevy/`
- At plugin creation time, fetch the `AssetsPlugin` and use [`AssetPlugin::file_path`](https://docs.rs/bevy/latest/bevy/prelude/struct.AssetPlugin.html#structfield.file_path) (misleading name *and* misleading docs) to get the relative path from the base path to the directory where the virtual file system takes root
- Put that in a `Resource` for later use
- On `SceneRoot` insertion, use `scene_root.path()?.path()` (sic) to get the virtual filesystem path
- Combine all of these to get the full path
- Call `fs::canonicalize` on it if we are feeling fancy

## What solution would you like?

Some API that returns a `Result` for getting the full path of an asset if and only if it was loaded from disk with a `FileAssetReader`.

## What alternative(s) have you considered?

Just leave it, I guess?

## Additional context

This will probably be important for editor development as well, if we wish to automatically load the same assets as a running program.

Also note that any solution involving fetching the `AssetReader` for a given asset will not currently work, as it cannot be downcast due to not being dyn compatible / object safe. We would need to add `as_foo_reader` methods for that to work.

Contributor guide

Open the contributing guide

Research direction

Start by reading FileAssetReader::get_base_path, AssetPlugin::file_path, and the AssetReader object-safety limitation described in the issue. Trace how SceneRoot exposes its virtual path and determine where a disk-only full-path API can fit; done means it returns a Result for FileAssetReader-backed assets without claiming support for Wasm, Android, or processed files.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.