-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Gizmos compatible with FixedUpdate #9153
Make Gizmos compatible with FixedUpdate #9153
Conversation
4011751
to
a18e12e
Compare
Wouldn't it make more sense to have a retained API for gizmos, e.g. |
I would say no mostly because I use these things as quick debug tools. Retained mode would add a lot of boilerplate here. The goal is just to have gizmos function intuitively in the fixed update. |
You are only fixing issue for fixed update, it wouldn't work for custom schedules, Perhaps gizmos should be retained {until next system run OR until 1 second is passed}? This solution would make gizmos work in all systems. But I'm not sure about performance implications of this approach. |
Putting aside any performance implications for now, that would mean gizmos persist after they're not wanted anymore (and would create an unintuitive distinction between not running the system and running the system but doing nothing inside).
To draw gizmos, you need to draw them once per 'frame' – this PR makes this work for both frame meaning "once per The only problem is when such schedules with their concept of 'frame' aren't build on |
dc1d642
to
f526697
Compare
Implemented. |
This PR is tagged for 0.11.1, but it might be worth just including the fix for Edit: Not anymore. |
Co-authored-by: Aceeri <[email protected]>
cd5cf5a
to
7deeba1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving minor suggestions and typos on some doc comments.
Co-authored-by: mnmaita <[email protected]>
This is sort of the direction that I lean towards. I don't think you should be drawing things to the screen during |
Could you clarify why?
I don't like it that things work in some cases but not in others. Why should you be able to use Gizmos normally in a variable-time game, but if you decide to switch to fixed time have it stop working? Or do you mean there shouldn't be an immediate mode API at all? In that case I agree with Aceeri.
With retained mode with Handles:
|
This is adding retained mode behavior to an immediate mode API. What if someone uses this expecting the gizmo to draw only on the frames the fixedupdate is running? That's how I would expect this to work, and this change would prevent that. Like, lets say I want to find the exact frame my updates are happening, visually, I would expect the gizmo would only display for the rendered frame the fixed update system is running. I could then record my screen to visually debug precisely when updates are happening. You can make gizmos work the way you want without any changes: // scheduled on a fixed update
fn update_pathfinding(mut pathfinding: ResMut<Pathfinding>) {}
// normally scheduled system
fn debug_pathfinding(mut gizmos: Gizmos, pathfinding: Res<Pathfinding>) {} |
The problem I have with this is that now you have boilerplate and friction to just debugging functionality. I can't just plop a line of code into my gameplay systems and debug it similar to a The way I see it is
I'm unsure of the point of that... Even in networking situations I am not using visual feedback. |
Ultimately, drawing things, especially in immediate mode, in FixedUpdate is fundamentally questionable. I think that your idea of "just use it like dbg" is good (and that "gameplay systems should be in FIxedUpdate by default"), but there are some real challenges here. FixedUpdate's behavior is uniquely strange, and with good reason. It may run once, zero or many times for a single frame. Once works fine out of the box. Your solution handles zero times, at the cost of substantial complexity. But what about multiple times? Your solution (and any non-retained solution) will then render multiple copies of the gizmos on the screen simultaneously, if only for a second. Ultimately, I think that the best solution here is to say "sorry, you can't use immediate mode drawing APIs within FixedUpdate", and then clearly document why and the workaround (split it out into another system that runs in Update). |
This doesn't render multiple copies of gizmos, it would clear each FixedUpdate frame, just as normal gizmos get cleared each rendering frame.
What if we just replicate the |
This came up in Discord: #8964 (which Aceeri referred to above) is similar in that it abstracts over different clocks. When that's merged, this PR could build upon it to do the same: |
# Objective Allow `Gizmos` to work in `FixedUpdate` without any changes needed. This changes `Gizmos` from being a purely immediate mode api, but allows the user to use it as if it were an immediate mode API regardless of schedule context. Also allows for extending by other custom schedules by adding their own `GizmoStorage<Clear>` and the requisite systems: - `propagate_gizmos::<Clear>` before `update_gizmo_meshes` - `stash_default_gizmos` when starting a clear context - `pop_default_gizmos` when ending a clear context - `collect_default_gizmos` when grabbing the requested gizmos - `clear_gizmos` for clearing the context's gizmos ## Solution Adds a generic to `Gizmos` that defaults to `Update` (the current way gizmos works). When entering a new clear context the default `Gizmos` gets swapped out for that context's duration so the context can collect the gizmos requested. Prior work: #9153 ## To do - [x] `FixedUpdate` should probably get its own First, Pre, Update, Post, Last system sets for this. Otherwise users will need to make sure to order their systems before `clear_gizmos`. This could alternatively be fixed by moving the setup of this to `bevy_time::fixed`? PR to fix this issue: #10977 - [x] use mem::take internally for the swaps? - [x] Better name for the `Context` generic on gizmos? `Clear`? --- ## Changelog - Gizmos drawn in `FixedMain` now last until the next `FixedMain` iteration runs.
Superseded by #10973
Objective
Gizmos are immediate mode and thus last only for one frame. When drawing them during
FixedUpdate
, multiple frames may be drawn before the next fixed update, causing them to flicker.Solution
Record fixed update gizmos separately and keep them around till the next update. This also works if there are multiple fixed updates in a single frame.
Also expose
GizmoBuffer
for any custom scheduling not covered by this.Alternatives
#10973 achieves the same by adding a generic parameter with a default value to Gizmos. While technically less flexible for extension as users can only store gizmo buffers based on their type instead of as values, I think that's sufficient and is a solution I'd be happy with.
Changelog
Added
GizmoBuffer
for recording gizmo draw callsFixed
FixedUpdate