Cant seem to get filters working correctly with my entities. #436
-
I'm new to Arche and am interested to see how it works, but I think I must be missing a step when working with filters. I get a new entity with Then I generate the components I need, populate them, and assign them with:
So far so good, and in fact if I query for everything, via:
I can see all the components, exactly as I expect them. However when I try to query based on a filter that I pre-created and registered via:
I get 0 entities in:
Am I missing a step? Am I just totally misunderstanding how this works? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
Hi @c-robinson, at first glance, all looks fine. But for the generic part that does not work for you, the code it too incomplete to actually judge. I can just guess that something is wrong with your ID lookup Regarding generic filters, registering them is not necessary and is only an optimization for cases where you have a very high number of archetypes (i.e. unique component combinations). Could you try your example without registering the filter? If that works, it is probably a bug in the filter cache. Could you please post a more complete reproducing example of what does not work for you? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Certainly, and thanks for the assistance!
Removed, am fetching via I have interfaces for the system types, for example:
Here's part of the implementation for the system that isn't working:
In my game scene initializer, I create an array of
And then I call them in my draw loop:
And that part all seems fine, i also have "UpdateSystems" that are created the exact same way, and my update loop is functioning correctly. Also it's weird that inside the Draw loop I can see all 3 target components fine, and that they are registered with the entity. The component that is failing seems to be
|
Beta Was this translation helpful? Give feedback.
-
I think I found it. Looks like Arche does not like slices? if I switch
It works. Trying to use |
Beta Was this translation helpful? Give feedback.
-
@c-robinson Thanks again for the entity initialization code you provided. I could now test it, and there is indeed an issue regarding slices. Looks like the problem is that, when creating components with already populated slices, the original slice gets garbage collected. This is a bit weird, as it seems to happen only in certain cases. As an example, when I print For some reason, it also works when creating and populating the entity with As a temporary workaround for the ID-based API, you can create your body := &ArticulatedBody{}
// ...
world.Assign(entity,
//...
)
body = (*ArticulatedBody)(world.Get(entity, bodyId))
body.Parts = append(body.Parts,
BodyPart{
Type: "torso",
Pivot: image.Point{0, 0},
},
)
body.Parts = append(body.Parts,
BodyPart{
Type: "head",
Pivot: image.Point{0, -20},
},
) |
Beta Was this translation helpful? Give feedback.
@c-robinson I think I fixed the issue. Could you give it a try with branch
fix-assign
main
(see PR #438)?