bevyengine / bevyengine/bevy

Loading custom materials in a resource sometimes fails

Open
#10,886 0 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version 0.12.1

Custom materials that are loaded in a resource sometimes doesn't work

## \[Optional\] Relevant system information

```
AdapterInfo { name: "NVIDIA GeForce RTX 3070", vendor: 4318, device: 9352, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "545.29.02", backend: Vulkan }
```

## What you did

I made a custom material based on the `custom_material_2d` example and put it in a plugin like this:
![image](https://github.com/bevyengine/bevy/assets/160317/7b4a71be-3428-4100-8e05-36c574045603)

The problem occurs when `init_resource` is called during `build` or outside the plugin, but not when called during `finish`.

I haven't tested if this happens with other asset types or the builtin materials.

## What went wrong

The material isn't loaded/doesn't work, nothing happens if I try to load it later, and no errors or other logging are printed.

If the problem turns out to be that you're not allowed to touch materials registered with `MaterialPlugin` before the plugin has been built, then I'd very much like a big notice in the documentation and some error logging, as this was a very hard problem to find in a big codebase. I also suspect that this behavior is new in 0.12 as I discovered this while updating.

## Additional information

I have made a repository that reproduces the problem here: https://github.com/kristoff3r/bevy-asset-bug/

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.