junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
769 stars 109 forks source link

[Question] Component construction/initialization with parameters #619

Closed hoxu closed 3 years ago

hoxu commented 3 years ago

I'm trying to use Monix Vars in Components instead of plain variables. For testing I need to be able to provide a different Scheduler, thus I need constructor parameters.

Even though EntityEdit.add looks like it allows constructing a Component with non-empty constructor, EntityEdit.add seems to first create the Component without constructor parameters before replacing it with the given Component. Moreover, the World constructor seems to choke on Components with no non-argument constructor:

com.artemis.InvalidComponentException: ExampleComponent: missing public constructor
    at com.artemis.ComponentTypeFactory.createComponentType(ComponentTypeFactory.java:65)
    at com.artemis.ComponentTypeFactory.getTypeFor(ComponentTypeFactory.java:54)
    at com.artemis.ComponentTypeFactory.getIndexFor(ComponentTypeFactory.java:100)
    at com.artemis.Aspect$Builder.associate(Aspect.java:359)
    at com.artemis.Aspect$Builder.build(Aspect.java:350)
    at com.artemis.EntitySubscription.<init>(EntitySubscription.java:32)
    at com.artemis.AspectSubscriptionManager.createSubscription(AspectSubscriptionManager.java:68)
    at com.artemis.AspectSubscriptionManager.get(AspectSubscriptionManager.java:64)
    at com.artemis.BaseEntitySystem.getSubscription(BaseEntitySystem.java:57)
    at com.artemis.BaseEntitySystem.setWorld(BaseEntitySystem.java:47)
    at com.artemis.WorldConfiguration.initialize(WorldConfiguration.java:171)
    at com.artemis.World.<init>(World.java:89)

Is there no way to use Components that require constructor parameters with artemis-odb?

genaray commented 3 years ago

Had the same issue... make sure you always have a public constructor without any params. Than it should work well :)

DaanVanYperen commented 3 years ago

Closing as answered.

hoxu commented 3 years ago

More like: component constructor parameters are not supported in artemis-odb.