diff --git a/source/DefaultEcs.Test/EntityTest.cs b/source/DefaultEcs.Test/EntityTest.cs index 6867c08f..9cabeb51 100644 --- a/source/DefaultEcs.Test/EntityTest.cs +++ b/source/DefaultEcs.Test/EntityTest.cs @@ -296,6 +296,22 @@ public void Set_Should_only_produce_one_component_for_flag_type() Check.That(world.Get().Length).IsEqualTo(1); } + [Fact] + public void Set_Should_override_SetSameAs() + { + using World world = new World(); + + Entity reference = world.CreateEntity(); + Entity entity = world.CreateEntity(); + + reference.Set(true); + entity.SetSameAs(reference); + entity.Set(false); + + Check.That(reference.Get()).IsTrue(); + Check.That(entity.Get()).IsFalse(); + } + [Fact] public void SetSameAs_Should_throw_When_Entity_not_created_from_World() { @@ -365,11 +381,11 @@ public void SetSameAs_Should_set_component_to_reference() Check.That(entity.Get()).IsEqualTo(reference.Get()); - reference.Set(true); + reference.Get() = true; Check.That(entity.Get()).IsEqualTo(reference.Get()); - entity.Set(false); + entity.Get() = false; Check.That(reference.Get()).IsEqualTo(entity.Get()); } @@ -530,7 +546,7 @@ public void Get_Should_get_component_of_reference_When_is_same_as() Check.That(entity.Get()).IsTrue(); - reference.Set(false); + reference.Get() = false; Check.That(entity.Get()).IsFalse(); } diff --git a/source/DefaultEcs/DefaultEcs.Release.csproj b/source/DefaultEcs/DefaultEcs.Release.csproj index 55b4c504..88892eaf 100644 --- a/source/DefaultEcs/DefaultEcs.Release.csproj +++ b/source/DefaultEcs/DefaultEcs.Release.csproj @@ -19,6 +19,8 @@ removed restriction on ManagedResource TResource to be IDisposable added AResourceManager.Unload to give the possibility to override the unload action for a resource + +fixed Entity.Set overriding shared component value \ No newline at end of file diff --git a/source/DefaultEcs/Technical/ComponentPool.cs b/source/DefaultEcs/Technical/ComponentPool.cs index 937d2718..567148a8 100644 --- a/source/DefaultEcs/Technical/ComponentPool.cs +++ b/source/DefaultEcs/Technical/ComponentPool.cs @@ -192,9 +192,14 @@ public bool Set(int entityId, in T component) ref int componentIndex = ref _mapping[entityId]; if (componentIndex != -1) { - _components[componentIndex] = component; + if (_links[componentIndex].ReferenceCount == 1) + { + _components[componentIndex] = component; - return false; + return false; + } + + Remove(entityId); } if (_lastComponentIndex == MaxCapacity - 1)