@@ -68,12 +68,9 @@ export class HashComponentIndex implements IComponentIndex {
6868 private _lastUpdated = Date . now ( ) ;
6969
7070 public addEntity ( entity : Entity ) : void {
71- const components = entity . components ;
72- const componentTypes = new Set < ComponentType > ( ) ;
73-
74- for ( const component of components ) {
75- const componentType = component . constructor as ComponentType ;
76- componentTypes . add ( componentType ) ;
71+ const componentTypes = entity . componentTypes ;
72+
73+ for ( const componentType of componentTypes ) {
7774
7875 let entities = this . _componentToEntities . get ( componentType ) ;
7976 if ( ! entities ) {
@@ -83,7 +80,7 @@ export class HashComponentIndex implements IComponentIndex {
8380 entities . add ( entity ) ;
8481 }
8582
86- this . _entityToComponents . set ( entity , componentTypes ) ;
83+ this . _entityToComponents . set ( entity , new Set ( componentTypes ) ) ;
8784 this . _lastUpdated = Date . now ( ) ;
8885 }
8986
@@ -229,9 +226,8 @@ export class BitmapComponentIndex implements IComponentIndex {
229226
230227 public addEntity ( entity : Entity ) : void {
231228 let bitmap = 0 ;
232-
233- for ( const component of entity . components ) {
234- const componentType = component . constructor as ComponentType ;
229+
230+ for ( const componentType of entity . componentTypes ) {
235231 let bit = this . _componentTypeToBit . get ( componentType ) ;
236232
237233 if ( bit === undefined ) {
0 commit comments