Fix CreateLookup throwing on same lookup creation

wip/no-type-lookup
copygirl 1 year ago
parent 948268e9ba
commit b93beed5ec
  1. 3
      src/gaemstone.ECS/Entity.cs

@ -50,7 +50,8 @@ public unsafe readonly partial struct Entity<TContext>
public Entity<TContext> CreateLookup<T>()
{
ref var lookup = ref Lookup<TContext>.Entity<T>.Value;
if (lookup.IsSome) throw new InvalidOperationException(
if (lookup == this) { /* Don't throw if lookup already has the same entity set. */ }
else if (lookup.IsSome) throw new InvalidOperationException(
$"The lookup for type {typeof(T)} in context {typeof(TContext)} is already in use by {lookup}");
lookup = this;
return this;

Loading…
Cancel
Save