Skip to content
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

removing relations #176

Open
Manborough opened this issue Feb 1, 2025 · 3 comments
Open

removing relations #176

Manborough opened this issue Feb 1, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@Manborough
Copy link

Is there a way to remove relations currently? I couldn't see a specific API and when I tried removing the component it didn't work, as relatedToEarth still shows two entities.

const world = createWorld();
const Asteroid = {
  preciousMetals: [] as boolean[],
};

const OrbitedBy = createRelation();
const IlluminatedBy = createRelation();
const earth = addEntity(world);
const moon = addEntity(world);
addComponent(world, moon, Asteroid);
Asteroid.preciousMetals[moon] = true;
const sun = addEntity(world);

addComponent(world, earth, OrbitedBy(moon));
addComponent(world, earth, IlluminatedBy(sun));
removeComponent(world, earth, IlluminatedBy(sun));
console.log(hasComponent(world, earth, IlluminatedBy(sun)));
const relatedToEarth = query(world, [Wildcard(earth)]);
console.log(relatedToEarth, "here");

P.S thanks for the quick fix on the other issue I raised, this library is very cool.

@mehaac
Copy link

mehaac commented Feb 5, 2025

removeComponent(world, earth, IlluminatedBy(sun));
removeComponent(world, sun, Pair(Wildcard, earth))

Not sure if this is the intended approach, but it worked in my case.

@Manborough
Copy link
Author

Neat, that does work. Seems like you only need the one removeComponent call too.

removeComponent(world, sun, Pair(Wildcard, earth));

@NateTheGreatt NateTheGreatt added the bug Something isn't working label Mar 7, 2025
@NateTheGreatt
Copy link
Owner

NateTheGreatt commented Mar 7, 2025

this is def a bug. thanks for the workaround @mehaac, and thanks for the catch @Manborough!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants