SceneTree and ECS has often been viewed incompatible or cumbersome.
But I recently discovered some concept that may allows to construct a Scene tree entirely from an ECS without too much performance loss (and for the connoisseurs, no I’m talking about mere parent-child components)
I’m actually talking about Abstract Query Filters
For those who may not know, a query in an ECS is a way to get all entities that have or doesn’t have some set of components.
Abstract query filters generalize to be able to get every entities that match an arbitrary predicate not just components.
However arbitrary predicate probably made you think about full linear scan of entities + virtual functions but no.
A way clever approach is to use bitsets that keeps track of entities matching the query.
I call this process soft query materialization
Materialization because we incrementally keeps tracks of entities matching the query and soft because that materialization doesn’t impact the memory layout of entities (in constrast to archetypes which are hard query materialization)
So now we may model a scene tree as a filtering layer above the ECS
Parents have a children filter
Childrens have the id of their parent
So we can now add that filter to any regular query and for example query evry children of a Node that has a rigidBody component but not an Input component.
And since this scene tree is entirely virtual it may have way better performances than godot actual implementation.
I have a project (but in the Nim programming language) that use this concept.
Would be happy to have you guys opinion on this idea and if it could probably empower godot.