How to change which material is pointed to by Handle<ColorMaterial> #12383
-
Hi! I'm trying to build a game where I have a bunch (order of millions) of tiles that can have a relatively small number of colors (~10). The tiles are all spawned using Of course I could have a unique material for each tile but that seems highly inefficient when what I really would like to do is simply point the existing material handle to a different material handle. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would store a central resource that lets you quickly and easily look up the handles: #[derive(PartialEq, Eq, Hash)]
enum TileType {
Grass,
Stone,
Dirt,
}
#[derive(Resource, Deref, DerefMut)
struct TileHandles(HashMap<TileType, Handle<ColorMaterial>>);
// Set your handles like
*tile_handle = tile_handles.get(TileType::Grass).unwrap().clone_weak(); |
Beta Was this translation helpful? Give feedback.
I would store a central resource that lets you quickly and easily look up the handles: