Spy-Shifty / BrokenBricksECS

Rebuild of Unity3D upcoming Entity Component System !OUT OF DEVELOPMENT!
MIT License
162 stars 28 forks source link

Trying to Destroy an entity gives a "Can't remove GameObjectEntity (Script) because..." error #12

Closed Gwindalmir closed 6 years ago

Gwindalmir commented 6 years ago

I have an entity that was part of the map on start, which has the GameObjectEntity ScriptBehaviour component on it as well as my own ECS components.

However when I try to delete it with EntityManager.DestroyEntity, I get an error:

Can't remove GameObjectEntity (Script) because ECSCharacterController (Script), Buildable (Script), Health (Script), Owner (Script), Selectable (Script), Moveable (Script), Rotatable (Script), AIModeData (Script), Sellable (Script), Unit (Script), Weapon (Script), ECSTransform (Script), ECSColliders (Script) depends on it

The above scripts I have assigned via the inspector. All of mine are ComponentDataWrappers, except ECSCharacterController, which is ComponentWrapper. The Transform component seems to have been removed, as I later get a "The given key was not present in the dictionary" error regarding ECS.TransformComponent. The Unity GameObject also remains in the world.

I don't recall exactly which commit this started with, but I don't believe this happened as of commit on Dec 28th.

Here's the code that deletes it: ` public class HealthSystem : ComponentSystem { [InjectDependency] private UnityEntityManager entityManager = null;

    // this will inject all entities with components of type MyComponent 
    // if you define multiple ComponentArrays with the [InjectTuple] tag
    // you will only receive those entities with both Components
    [InjectTuple]
    ComponentArray<HealthComponent> healthComponentArray;

    // Use this for standard unity update function
    public override void OnUpdate()
    {
        for (int i = 0; i < healthComponentArray.Length; i++)
        {
            // If health is at or below 0, destroy entity
            if (healthComponentArray[i].health <= 0)
                entityManager.DestroyEntity(healthComponentArray.GetEntity(i));
            // Make sure health is no higher than max health
            else if (healthComponentArray[i].health > healthComponentArray[i].maxHealth)
                entityManager.SetComponent(healthComponentArray.GetEntity(i), new HealthComponent() { health = healthComponentArray[i].maxHealth, maxHealth = healthComponentArray[i].maxHealth });
        }
    }
}

`

Spy-Shifty commented 6 years ago

Thank you for reporting!

I'm on it!

Spy-Shifty commented 6 years ago

Sorry that this took so long! But it is fixed now! 59a5dd27e8c71a73f39f7671705dcda7cb6a3ccf