diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs
index c2a0532..ca188b6 100644
--- a/encompass-cs/Engine.cs
+++ b/encompass-cs/Engine.cs
@@ -164,7 +164,7 @@ namespace Encompass
}
///
- /// Returns an Entity containing the specified Component type.
+ /// Returns an Entity containing the specified Component type.
///
protected Entity ReadEntity() where TComponent : struct, IComponent
{
@@ -173,7 +173,7 @@ namespace Encompass
}
///
- /// Returns all Entities containing the specified Component type.
+ /// Returns all Entities containing the specified Component type.
///
protected IEnumerable ReadEntities() where TComponent : struct, IComponent
{
@@ -250,7 +250,7 @@ namespace Encompass
}
///
- /// Returns a Component with the specified Component Type. If multiples exist, an arbitrary Component is returned.
+ /// Returns a Component with the specified Component Type. If multiples exist, an arbitrary Component is returned.
///
protected (Guid, TComponent) ReadComponent() where TComponent : struct, IComponent
{
@@ -488,7 +488,7 @@ namespace Encompass
}
///
- /// Overwrites Component struct data associated with the specified Component ID.
+ /// Overwrites Component struct data associated with the specified Component ID.
///
protected Guid SetComponent(Guid componentID, TComponent component) where TComponent : struct, IComponent
{
@@ -496,7 +496,7 @@ namespace Encompass
}
///
- /// Sets Draw Component data for the specified Component Type on the specified Entity.
+ /// Sets Draw Component data for the specified Component Type on the specified Entity.
/// This method must be used for the Draw Component to be readable by an OrderedRenderer.
/// If Component data for this Type already existed on the Entity, the component data is overwritten.
///
@@ -657,6 +657,16 @@ namespace Encompass
}
}
+ ///
+ /// Removes a Component with the specified type from the given Entity.
+ /// Note that the Engine must Read the Component type that is being removed.
+ ///
+ protected void RemoveComponent(Entity entity) where TComponent : struct, IComponent
+ {
+ var (componentID, _) = GetComponent(entity);
+ RemoveComponent(componentID);
+ }
+
///
/// Removes the Component with the specified ID from its Entity.
///
diff --git a/test/EngineTest.cs b/test/EngineTest.cs
index 2df6c85..5e44883 100644
--- a/test/EngineTest.cs
+++ b/test/EngineTest.cs
@@ -1117,5 +1117,38 @@ namespace Tests
readEntities.Should().BeEmpty();
}
+
+ [Reads(typeof(MockComponent))]
+ class RemoveComponentByTypeEngine : Engine
+ {
+ public override void Update(double dt)
+ {
+ foreach (var (_, _, entity) in ReadComponentsIncludingEntity())
+ {
+ RemoveComponent(entity);
+ }
+ }
+ }
+
+ [Test]
+ public void RemoveComponentByType()
+ {
+ var worldBuilder = new WorldBuilder();
+ worldBuilder.AddEngine(new ReadComponentsTestEngine());
+ worldBuilder.AddEngine(new RemoveComponentByTypeEngine());
+
+ var entity = worldBuilder.CreateEntity();
+ worldBuilder.SetComponent(entity, new MockComponent { });
+
+ var entityB = worldBuilder.CreateEntity();
+ worldBuilder.SetComponent(entity, new MockComponent { });
+
+ var world = worldBuilder.Build();
+
+ world.Update(0.01);
+ world.Update(0.01);
+
+ resultComponents.Should().BeEmpty();
+ }
}
}