bevy: Can't change title at runtime.
Bevy version
rev = “d158e0893ea88b6acf523a4264f076d6e0b540c6”
Operating system & version
Linux Mint 20.1 Ulyssa
What you did
I tried to change the window title:
fn update_title(score: Res<Score>, mut window: ResMut<WindowDescriptor>) {
window.title = format!("Snake: {}", score.0);
}
What you expected to happen
I expected the title to change.
What actually happened
The title stayed the same.
Additional information
I am using a WindowDescriptor to set the title at startup.
Window::set_title
works, but is more verbose.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (20 by maintainers)
Commits related to this issue
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to bevyengine/bevy by cart 2 years ago
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to bevyengine/bevy by cart 2 years ago
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to bevyengine/bevy by cart 2 years ago
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to james7132/bevy by cart 2 years ago
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to Pietrek14/bevy by cart 2 years ago
- Plugins own their settings. Rework PluginGroup trait. (#6336) # Objective Fixes #5884 #2879 Alternative to #2988 #5885 #2886 "Immutable" Plugin settings are currently represented as normal ECS... — committed to ItsDoot/bevy by cart 2 years ago
There are a couple points to this.
The first is that it represents an unintuitive way of using resources*, but we have considered a special
app.insert_setup_resource()
method or better docs or renaming the type.*unintuitive because:
DefaultPlugins
DefaultPlugins
, it crashes when you try to change it b. if you had inserted it afterDefaultPlugins
, it fails silently when you try to change itThe second is that there are already several examples of having more than one way to do the same thing. In the best cases, there is usually an easy way in the general case, and a harder (more verbose) way that’s more flexible.
Text::with_section()
vsText { .. }
Res<Input<KeyCode>>
vsEventReader<KeyboardInput>
input.any_pressed([a, b, c])
vsinput.pressed(a) || input.pressed(b)) || input.pressed(c))
This:
represents an easy way in the general case (having one window). It’s easier because it’s intuitive: it matches the way that you initialise the window settings, and it matches the way you initialise and make changes to other resources (and components).
WindowDescriptor
tracking would likely build on top ofWindows
sure, but I don’t see there being a problem of building one abstraction on top of another: look atInput<KeyCode>
, which is a stateful abstraction over theKeyboardInput
event.Do you gain much by having that ^ over this:
One less line perhaps, but other than that, nothing more than what’s already been discussed: I think the question is whether the clarity and usability win is enough.
I made comments on this topic earlier in the year https://github.com/bevyengine/bevy/issues/1255#issuecomment-771837798
My view for the specific issue at hand:
WindowDescriptor
(if that’s the resource used) ideally should be an “active” resource, in the same way asClearColor
. A user simply updates a resource, and things just work. This could be as simple as a system added toWindowPlugin
that monitors changes toRes<WindowDescriptor>
, and automatically applies the appropriatewindow.set_*
methods.WindowDescriptor
only applies to a single window, sure, but so doesClearColor
.I made a prototype of this a while ago (just updated to work with latest main)
I believe that is exactly what https://github.com/bevyengine/bevy/pull/5589 does.