oxygen
oxygen copied to clipboard
Components cant be removed but can be marked for removal?
Current bug behaviour
If I add a component and then remove it, it does not get removed.
Expected behaviour
A component marked for removal would be removed.
Steps to reproduce
import 'package:oxygen/oxygen.dart';
import 'package:test/test.dart';
class TestComponent extends ValueComponent<void> {}
class ComponentAdderSystem extends System {
late Query query;
@override
void init() {
query = createQuery([HasNot<TestComponent>()]);
}
@override
void execute(double delta) {
for (final entity in query.entities) {
entity.add<TestComponent, void>();
}
}
}
class ComponentRemoverSystem extends System {
late Query query;
@override
void init() {
query = createQuery([Has<TestComponent>()]);
}
@override
void execute(double delta) {
for (final entity in query.entities) {
entity.remove<TestComponent>();
}
}
}
void main() {
group('Component', () {
test('Components should be added and removed from entities.', () {
final world = World();
world.registerComponent<TestComponent, void>(() => TestComponent());
world.registerSystem(ComponentRemoverSystem());
world.registerSystem(ComponentAdderSystem());
var testEntity = world.createEntity('Test Entity');
world.init();
expect(false, testEntity.has<TestComponent>(),
reason: 'Entity has component it shouldnt.');
world.execute(1);
testEntity = world.entities.first;
expect(true, testEntity.has<TestComponent>(),
reason: 'Entity does not have required component.');
world.execute(1);
testEntity = world.entities.first;
expect(false, testEntity.has<TestComponent>(),
reason: 'Entity has component it shouldnt.');
});
});
}
More environment information
- Oxygen version: 0.2.0
More information
I created a fork where I made the changes that I thought would be needed here:
https://github.com/billHaggerty/oxygen/blob/main/lib/src/world.dart#L66 https://github.com/billHaggerty/oxygen/blob/main/lib/src/entity/entity_manager.dart#L157 https://github.com/billHaggerty/oxygen/blob/main/lib/src/entity/entity_manager.dart#L165 https://github.com/billHaggerty/oxygen/blob/main/lib/src/entity/entity_manager.dart#L112
This all seems like it was supposed to work. The components to be removed were being tracked but I couldn't see what was supposed to actually remove them. If I was missing something please let me know.
I'm having issues with this bug as well. Any updates on if it will get fixed, or if I am using add/remove components wrong?
I just ran into this issue as well. Tried removing a component and my system kept updating that entity. ~~Looks like for now I'll have to clone flame_oxygen and modify it for now to use your oxygen fork~~
I just needed to add your fork as a dependency of my project, forcing that as the only version.
Looks like in order to get this to actually work with flame_oxygen I had to add the new component removal function to FlameWorld's update function, since it doesn't use World's execute for some reason...