I have a strong feeling this is just an error on my behalf, but I have been hunting this down for quite some time and can't figure out what's going wrong here.
I'm working on a small editor that uses Artemis as its core. When an "Add" button is clicked on the UI, a new entity is created along with a default set of components:
private ComponentMapper<SpriteReference> spriteReferences;
void addClicked() {
World world = editorGameContainer.getWorld();
int id = world.create();
SpriteReference ref = spriteReferences.create(id);
ref.region = "white";
Transform t = transforms.create(id);
t.position.set(camera.position.x - 0.5f, camera.position.y - 0.5f, 0f);
}
This works fine and dandy, and the entity appears. Now, clicking on the sprite of the entity selects the entity and populates the UI with all the components of the entity. This works just fine. Now, each component entry on the UI has a "remove" button, which should remove the component.
Class<? extends Component> c = component.getClass();
ImageButton btnRemove = ...;
btnRemove.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
ComponentRef cref = c.getAnnotation(ComponentRef.class);
if (cref != null) world.edit(id).remove(cref.value());
world.edit(id).remove(c);
}
});
This seems to "work", but it's not consistent. If I remove the Transform component, the entity disappears and the interested systems are notified via removed(int id) method. However, with the SpriteReference component, it's a tad more complicated.
The SpriteReference component is basically just a serialization-friendly component that tells what kind of sprite the actual SpriteComponent should use. The two components are like this, first the SpriteReference:
@ComponentRef(SpriteComponent.class)
@PooledWeaver
public class SpriteReference extends Component {
public String region = "";
}
And the SpriteComponent:
@Transient
@NonEditable
@PooledWeaver
public class SpriteComponent extends Component {
public Sprite sprite;
}
The relationship is managed by AssetReferenceManager:
This all works when the entity is created, but for some reason, the other systems (e.g. SpriteSystem with Aspect.all(SpriteComponent.class, Transform.class) subscription) are not notified when the SpriteReference and SpriteComponent components are removed - the SpriteSystem keeps drawing the sprite even though the components are removed.
On the other hand, if I remove the Transform component, the SpriteSystem gets notified and won't draw the sprite anymore. Also, if I regenerate the UI list of components, the SpriteReference and SpriteComponent components are removed altogether. It's just weird that the SpriteSystem still draws the sprites.
I'm not sure if it's of any relevance, but here's the SpriteSystem that still keeps drawing (with the relevant code left and otherwise pruned):
I have a strong feeling this is just an error on my behalf, but I have been hunting this down for quite some time and can't figure out what's going wrong here.
I'm working on a small editor that uses Artemis as its core. When an "Add" button is clicked on the UI, a new entity is created along with a default set of components:
This works fine and dandy, and the entity appears. Now, clicking on the sprite of the entity selects the entity and populates the UI with all the components of the entity. This works just fine. Now, each component entry on the UI has a "remove" button, which should remove the component.
This seems to "work", but it's not consistent. If I remove the
Transform
component, the entity disappears and the interested systems are notified viaremoved(int id)
method. However, with theSpriteReference
component, it's a tad more complicated.The
SpriteReference
component is basically just a serialization-friendly component that tells what kind of sprite the actualSpriteComponent
should use. The two components are like this, first theSpriteReference
:And the
SpriteComponent
:The relationship is managed by
AssetReferenceManager
:This all works when the entity is created, but for some reason, the other systems (e.g.
SpriteSystem
withAspect.all(SpriteComponent.class, Transform.class)
subscription) are not notified when theSpriteReference
andSpriteComponent
components are removed - theSpriteSystem
keeps drawing the sprite even though the components are removed.On the other hand, if I remove the
Transform
component, theSpriteSystem
gets notified and won't draw the sprite anymore. Also, if I regenerate the UI list of components, theSpriteReference
andSpriteComponent
components are removed altogether. It's just weird that theSpriteSystem
still draws the sprites.I'm not sure if it's of any relevance, but here's the
SpriteSystem
that still keeps drawing (with the relevant code left and otherwise pruned):I'm really at my wit's end here. Any ideas?