aevyrie / bevy_mod_raycast

A little mesh raycasting plugin for Bevy
https://crates.io/crates/bevy_mod_raycast
MIT License
303 stars 92 forks source link

No hit when used in `PostUpdate` system #114

Closed thmxv closed 1 month ago

thmxv commented 1 month ago

I use the immediate mode to cast rays in a system and it works well if the system is in Update. However I needed to move this system to PostUpdate (for reasons unrelated to this mod but related to egui) and, with this change, the ray cast never returns any hit. Is this a known/normal limitation (but undocumented) or is this a bug?

aevyrie commented 1 month ago

I can't replicate this. Setting the raycasting system in minimal to run in PostUpdate works just fine.

Edit: also checked mouse_picking and reflecting_laser.

thmxv commented 1 month ago

Thanks and sorry. I thought it was replicated in the minimal example for some weird reasons but that is not the case. Pretty dumb on my part.

However. In my camera controller, I use a ray-cast from the mouse cursor to rotate/orbit around the intersection of the ray-cast with the geometry (like in Blender with auto_depth enabled). This works well if the camera controller system is in Update but not if it is in PostUpdate. The Res<CursorRay> has a correct origin and direction but the (immediate) cast_ray() does return an empty slice of intersection.

Any way, thanks for checking and correcting my mistake and thanks a lot for this mod.

aevyrie commented 1 month ago

That is possibly happening if you are running the raycast after bevy's transform propagation happens in PostUpdate.

thmxv commented 1 month ago

Thanks (once again). But no the system is set to run

...
    .before(CameraUpdateSystem)
    .before(TransformSystem::TransformPropagate),
thmxv commented 1 month ago

So weird:

I do not know what to do really. It is probably due to some other issue of system ordering that can reappear at a latter stage.

aevyrie commented 1 month ago

If it's inconsistent, it's likely a system ordering ambiguity, and can differ from run to run. I'd suggest taking a look at the ambiguity checker.