Model for Serialization - junkdog/artemis-odb GitHub Wiki
Ideally serialize references to assets instead of the assets themselves. Separating reference components and asset components keeps your serialized world lean.
Example
When using Spine, create a separate SpineReference and SpineRenderable component.
@Transient
public class SpineRenderable extends Component {
public AnimationState state;
public Skeleton skeleton;
}
@PooledWeaver
public final class SpineReference extends Component {
public String path; // <- trivially serializable
}
@Transient exempts the component from serialization.
Create a system for each reference-asset pair which listens for unpaired references.
public class SpineResolver extends BaseEntitySystem {
public SpineResolver() {
super(all(Size.class, SpineReference.class).exclude(SpineRenderable.class));
}
@Override
protected void processSystem() {}
@Override
protected void inserted(int id) {
// once inserted, aspect.exclude(SpineRenderable.class) is longer satisfied.
// removing the SpineRenderable would immediately recreate it; can be useful
// when dealing with reloaded textures, editor tooling etc.
assignSpine(id);
}
}