Closed arnaud-secondlayer closed 2 years ago
I'm not exactly sure I understand what you are trying to do.
But maybe overriding the added
/deleted
function of a system or manager and only add the entities with the Component/or unrefactored data and use that instead of using mappers? Though you won't be able to react to removed/added components.
Or maybe oxygen is a better fit? It has a get<Component>()
function on Entity
.
Is having this function exposed what you would want: https://github.com/denniskaselow/dartemis/blob/8c8bc149231e448369108de3674548afe6e0d08a/lib/src/core/component_manager.dart#L70 (It no longer exists, but I think it should still work if I add it again).
Yes, that's exactly the function I would need. Maybe return T?
, but that's the idea.
Ok, I'll add the function. That code was before null safety, so yeah, it'll be T?. Shouldn't take long.
Done. Use it like this:
final componentType = ComponentType.getTypeFor(MyComponent);
final component = world.componentManager.getComponent<MyComponent>(entity, componentType);
I think there is an issue in getComponent
when entity
is larger than _ComponentInfo.components
or if components[entity]
is null
.
Sorry about that :(.
A new version with a fix has been published. If it doesn't work and there are still exceptions, please include the stacktrace too. Thank you.
I'm trying to migrate an existing system to dartemis. The system is large enough that I have to spread the migration other several weeks/months. One problem I'm facing right now is that I started splitting my large classes data into components, but most of my code doesn't live in systems yet. In order to access the component data, I'm using mappers, but I cannot always refactor my code to benefit from mappers, and creating a mapper just to decide if an entity has one component or retrieve one field from a component is expensive.
I was wondering if it was possible to add a function to retrieve a
Component?
given an entity without creating a mapper. I know it will not be as fast as mappers in systems, but it should be faster when accessing data in a more randomized fashion.