Skip to content

Insertion and Mutation of different Components on the same EntityMut #4155

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

Closed
Zeenobit opened this issue Mar 8, 2022 · 2 comments
Closed
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior S-Duplicate This issue or PR already exists

Comments

@Zeenobit
Copy link
Contributor

Zeenobit commented Mar 8, 2022

Bevy version

0.6

Operating system & version

Windows 10 64-bit

What you did

The following assertion fails if I uncomment the line mentioned in the snippet below:

fn what() {
    #[derive(Component)]
    struct Dummy(u64);

    #[derive(Component)]
    struct OtherDummy;

    let mut world = World::default();
    let entity: Entity;

    {
        entity = world.spawn().insert(Dummy(0)).id();
    }

    {
        let mut entity = world.entity_mut(entity);
        let mut dummy = entity.get_mut::<Dummy>().unwrap();
        //entity.insert(OtherDummy); <--- Uncommenting this line makes the test fail?!
        dummy.0 = 12;
    }

    {
        let entity = world.entity(entity);
        let dummy = entity.get::<Dummy>().unwrap();

        assert_eq!(dummy.0, 12);
    }
}

What you expected to happen

Insertion or removal of an unrelated component shouldn't change the result of the test.

What actually happened

The test doesn't fails because value of dummy is not set correctly.

Additional information

This issue was raised from a discussion on Discord:
https://discord.com/channels/691052431525675048/950812276712165416

As a workaround, re-ordering the insertion/mutation steps seems to pass the test:

fn what() {
    #[derive(Component)]
    struct Dummy(u64);

    #[derive(Component)]
    struct OtherDummy;

    let mut world = World::default();
    let entity: Entity;

    {
        entity = world.spawn().insert(Dummy(0)).id();
    }

    {
        let mut entity = world.entity_mut(entity);
        entity.insert(OtherDummy);
        let mut dummy = entity.get_mut::<Dummy>().unwrap();
        dummy.0 = 12;
    }

    {
        let entity = world.entity(entity);
        let dummy = entity.get::<Dummy>().unwrap();

        assert_eq!(dummy.0, 12);
    }
}
@Zeenobit Zeenobit added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 8, 2022
@DJMcNab
Copy link
Member

DJMcNab commented Mar 8, 2022

Duplicate of #3408

@DJMcNab DJMcNab marked this as a duplicate of #3408 Mar 8, 2022
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events and removed S-Needs-Triage This issue needs to be labelled labels Mar 8, 2022
@DJMcNab DJMcNab added the S-Duplicate This issue or PR already exists label Mar 8, 2022
@hymm
Copy link
Contributor

hymm commented Mar 8, 2022

Can confirm this is fixed by #3001. Should close this out in favor of the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior S-Duplicate This issue or PR already exists
Projects
None yet
Development

No branches or pull requests

4 participants