Closed tricarbonate closed 6 months ago
Yes, you need to read meshes to be able to raycast them, so you will need to split your system apart into smaller systems, or convert your mesh mutations into Command
s.
My recommendation would be to split this up into smaller systems that do just one thing. E.g. a system that raycasts against things and either sends events, updates components, or updates a resource to track what things have been hit and the semantic significance of the hit (such as "this is a list of things hit by the players gun this frame"). You would then use this event/component/resource in the next system that processes this information.
I have a ray cast system that spawns new meshes when the ray hits certain objects. But the Raycast accesses the meshes (with Res<Assets>), so it is not possible to use ResMut<Assets> in the same system because it would cause error B0002 (see https://bevyengine.org/learn/errors/#b0002)
I have a system that looks like this:
The access with mut meshes: ResMut<Assets> causes B0002 but I'm probably missing a better way of doing this