SanderMertens / flecs

A fast entity component system (ECS) for C & C++

Home Page:https://www.flecs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclusive relationship in a prefab that's marked as an override is not overridden if the entity already has the relationship added

pfeodrippe opened this issue · comments

Describe the bug
Exclusive relationship in a prefab that's marked as an override is not overridden if the entity already has the relationship added.

  1. An entity has an exclusive relationship
  2. A prefab has this exclusive relationship as well
  3. Add a (IsA, prefab) to the entity
  4. Now entity has 2 two relationships for the exclusive rel.

To Reproduce
I'm testing it with some Clojure code as I'm doing a wrapper for Flecs (the C api), but it should be readable by you (let me know if it's not and then I can try to work on some C), see below.

;; -------- This works fine ------
(def world (vy/init))
;; `vy/add-c` receives the world, the entity and the component.
(vy/add-c world :vy.c/visibility :vy.b/EcsExclusive)

;; Prefab components (in this case) have the ECS_OVERRIDE flag set!
;; `vy/add-prefab` receives the world, the entity and components (plural!)
(vy/add-prefab world :vy.pf/sprite [[:vy.c/visibility :vy.visibility/inherited]])

;; `[...]` is a pair.
(vy/add-c world :pitoco [:vy.b/EcsIsA :vy.pf/sprite])
(vy/add-c world :pitoco [:vy.c/visibility :vy.visibility/inherited])

;; This is analogous to `ecs_entity_str`.
(vy/entity-info world :pitoco)
;; =>
[:vy.b/EcsTag
 [:vy.b/EcsIsA :vy.pf/sprite]
 [:vy.c/visibility :vy.visibility/inherited]]

;; -------- This has the bug ------
(def world (vy/init))
(vy/add-c world :vy.c/visibility :vy.b/EcsExclusive)

;; Prefab components (in this case) have the ECS_OVERRIDE flag set!
(vy/add-prefab world :vy.pf/sprite [[:vy.c/visibility :vy.visibility/inherited]])

(vy/add-c world :pitoco [:vy.c/visibility :vy.visibility/hidden])
;; Note that we add the sprite AFTER adding the `[:vy.c/visibility :vy.visibility/hidden]` pair to the entity `:pitoco`.
(vy/add-c world :pitoco [:vy.b/EcsIsA :vy.pf/sprite])

(vy/entity-info world :pitoco)
;; =>
[:vy.b/EcsTag
 [:vy.b/EcsIsA :vy.pf/sprite]
 [:vy.c/visibility :vy.visibility/inherited]
 [:vy.c/visibility :vy.visibility/hidden]]

;; When I add the component again, it seems as it will work.
(vy/add-c world :pitoco [:vy.c/visibility :vy.visibility/hidden])
(vy/entity-info world :pitoco)
;; =>
[:vy.b/EcsTag
 [:vy.b/EcsIsA :vy.pf/sprite]
 [:vy.c/visibility :vy.visibility/hidden]]

;; But then it doesn't.
(vy/add-c world :pitoco [:vy.c/visibility :vy.visibility/inherited])
(vy/entity-info world :pitoco)
;; =>
[:vy.b/EcsTag
 [:vy.b/EcsIsA :vy.pf/sprite]
 [:vy.c/visibility :vy.visibility/inherited]
 [:vy.c/visibility :vy.visibility/hidden]]

Expected behavior
I would expect the prefab addition to not add a second component (maybe it's considering things as different components because of the OVERRIDE flag?).

Thanks for this lib, it's awesome and fast! Great work \o/

This is a bit hard to read 😅 let me try to reproduce from your description.

EDIT: reproduced, nice catch!

This is a bit hard to read 😅 let me try to reproduce from your description.

EDIT: reproduced, nice catch!

Ahahahahahahahahahahaha thank you o/

Fixed!

Ohhh it was fast, bonus is that now you basically know Clojure ahahahahaah thank you for the wonderful work, man o/