diff --git a/ecs/query.go b/ecs/query.go index 3de4beb3..af4205fa 100644 --- a/ecs/query.go +++ b/ecs/query.go @@ -166,8 +166,12 @@ func (q *Query) Mask() Mask { } // Ids returns the component IDs for the archetype of the [Entity] at the iterator's current position. +// +// Returns a copy of the archetype's component IDs slice, for safety. +// This means that the result can be manipulated safely, +// but also that calling the method may incur some significant cost. func (q *Query) Ids() []ID { - return q.archetype.node.Ids + return append([]ID{}, q.archetype.node.Ids...) } // Close closes the Query and unlocks the world. diff --git a/ecs/world.go b/ecs/world.go index 634502ec..190c0ff0 100644 --- a/ecs/world.go +++ b/ecs/world.go @@ -1045,11 +1045,15 @@ func (w *World) Mask(entity Entity) Mask { } // Ids returns the component IDs for the archetype of the given [Entity]. +// +// Returns a copy of the archetype's component IDs slice, for safety. +// This means that the result can be manipulated safely, +// but also that calling the method may incur some significant cost. func (w *World) Ids(entity Entity) []ID { if !w.entityPool.Alive(entity) { panic("can't get mask for a dead entity") } - return w.entities[entity.id].arch.node.Ids + return append([]ID{}, w.entities[entity.id].arch.node.Ids...) } // ComponentType returns the reflect.Type for a given component ID, as well as whether the ID is in use.