Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

Polymorphism of systems #29

Open
enzi opened this issue Feb 26, 2018 · 2 comments
Open

Polymorphism of systems #29

enzi opened this issue Feb 26, 2018 · 2 comments

Comments

@enzi
Copy link

enzi commented Feb 26, 2018

Currently I have an EquipmentEngineBase : ComponentSystem and

  • EquipmentEngine : EquipmentEngineBase
  • UnEquipmentEngine : EquipmentEngineBase

When I add these 2 systems the ECS throws an error in ComponentGroup.cs, the type has already been added to the dictionary.
A check if it already contains this type is sufficient and both systems work correctly. I just wonder if it has any negative side effects.

The full code:

    public ComponentGroup(EntityManager entityManager, params Type[] componentTypes) {
        _entityManager = entityManager;
        _groupMatcher = new GroupMatcher(componentTypes);

        foreach (Type type in componentTypes) {
            Type componentArrayType = typeof(ComponentArray<>);
            Type genericComponentArrayType = componentArrayType.MakeGenericType(type);
            
            if (!_components.ContainsKey(type)) // added
                _components.Add(type, (ComponentArray)Activator.CreateInstance(genericComponentArrayType));                
        }
    }
@Spy-Shifty
Copy link
Owner

How do you add your systems?

@enzi
Copy link
Author

enzi commented Feb 26, 2018

Nothing special
with
AddSystem<EquipmentEngine>(); AddSystem<UnEquipmentEngine>();

in public class MainCore : ECSController<UnityStandardSystemRoot, UnityEntityManager>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants