public static uint UpdateArchetype(ArchetypeBoardContainer archetypeBoard, ComponentTypeBoardContainer componentTypeBoard, EntityBoardContainer entityBoard, GameEntityHandle entityHandle) { var typeSpan = componentTypeBoard.Registered; var foundIndex = 0; Span <uint> founds = stackalloc uint[typeSpan.Length]; for (var i = 0; i != typeSpan.Length; i++) { var metadataSpan = entityBoard.GetComponentColumn(typeSpan[i].Id); /*if (metadataSpan.Length <= entityHandle.Id) TODO:: if it bug again, just uncomment this * continue;*/ if (metadataSpan[(int)entityHandle.Id].Valid) { founds[foundIndex++] = typeSpan[i].Id; } } if (foundIndex > 128) { throw new InvalidOperationException("What are you trying to do with " + foundIndex + " components?"); } var archetype = archetypeBoard.GetOrCreateRow(founds.Slice(0, foundIndex), true); var currentArchetype = entityBoard.ArchetypeColumn[(int)entityHandle.Id]; if (currentArchetype.Id != archetype) { entityBoard.AssignArchetype(entityHandle.Id, archetype); if (currentArchetype.Id > 0) { archetypeBoard.RemoveEntity(currentArchetype.Id, entityHandle.Id); } archetypeBoard.AddEntity(archetype, entityHandle.Id); } return(archetype); }