-
Notifications
You must be signed in to change notification settings - Fork 2
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
Creating a View if Entity matches the Filter of a Kind _after_ it was already spawned. #2
Comments
In theory, this should already work. I need to add test coverage for it, so I'm not 100% sure.
If your component is added as a viewable (i.e. Let me know if your observation is different please! |
I just did a quick test to sanity check this. It should already work as is: use bevy::prelude::*;
#[derive(Component)]
struct M;
impl BuildView for M {
fn build(_world: &World, _object: Object<Self>, mut view: ViewCommands<Self>) {
view.insert(V);
}
}
#[derive(Component)]
struct MX;
impl BuildView<M> for MX {
fn build(_world: &World, _object: Object<M>, mut view: ViewCommands<M>) {
view.insert(VX);
}
}
#[derive(Component)]
struct V;
#[derive(Component)]
struct VX;
#[test]
fn add_view() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_viewable::<M>()
.add_view::<M, MX>();
let m = app.world_mut().spawn(M).id();
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(!v.contains::<VX>());
}
app.world_mut().entity_mut(m).insert(MX);
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(v.contains::<VX>());
}
} |
Oops I apologize, I'm sure it was a user error! I ended up fixing it on my
end by doing things differently anyway (and more sanely).
Thanks btw this is a great crate! (Along the other moonshine suite of
crates)
…On Tue, 18 Mar 2025, 21.15 Zeenobit, ***@***.***> wrote:
I just did a quick test to sanity check this. It should already work as is:
use bevy::prelude::*;
#[derive(Component)]
struct M;
impl BuildView for M {
fn build(_world: &World, _object: Object<Self>, mut view: ViewCommands<Self>) {
view.insert(V);
}
}
#[derive(Component)]
struct MX;
impl BuildView<M> for MX {
fn build(_world: &World, _object: Object<M>, mut view: ViewCommands<M>) {
view.insert(VX);
}
}
#[derive(Component)]
struct V;
#[derive(Component)]
struct VX;
#[test]
fn add_view() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_viewable::<M>()
.add_view::<M, MX>();
let m = app.world_mut().spawn(M).id();
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(!v.contains::<VX>());
}
app.world_mut().entity_mut(m).insert(MX);
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(v.contains::<VX>());
}
}
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKEEGFGUXOPQBBUUW72IED2VBWDLAVCNFSM6AAAAABZEEGUV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZUGQ2TKMRZGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
[image: Zeenobit]*Zeenobit* left a comment (Zeenobit/moonshine_view#2)
<#2 (comment)>
I just did a quick test to sanity check this. It should already work as is:
use bevy::prelude::*;
#[derive(Component)]
struct M;
impl BuildView for M {
fn build(_world: &World, _object: Object<Self>, mut view: ViewCommands<Self>) {
view.insert(V);
}
}
#[derive(Component)]
struct MX;
impl BuildView<M> for MX {
fn build(_world: &World, _object: Object<M>, mut view: ViewCommands<M>) {
view.insert(VX);
}
}
#[derive(Component)]
struct V;
#[derive(Component)]
struct VX;
#[test]
fn add_view() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_viewable::<M>()
.add_view::<M, MX>();
let m = app.world_mut().spawn(M).id();
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(!v.contains::<VX>());
}
app.world_mut().entity_mut(m).insert(MX);
app.update();
{
let w = app.world();
let v = w.entity(w.get::<Viewable<M>>(m).unwrap().view().entity());
assert!(v.contains::<V>());
assert!(v.contains::<VX>());
}
}
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKEEGFGUXOPQBBUUW72IED2VBWDLAVCNFSM6AAAAABZEEGUV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZUGQ2TKMRZGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi!
If I'm not mistaken, if an entity gets components added later, after spawn, to make it match a Kind Filter, whereas it didn't before, the View never spawns for this Entity.
Is this desired behaviour, and if so, should it perhaps be documented?
That said, if it's possible to add this feature, that would be very handy.
(I might be wrong about this, but I tried it out, and looked through the source and didn't at least see such functionality)
The text was updated successfully, but these errors were encountered: