Possibly an ECS powered SceneTree for Godot

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.

1 Like

How would the underlying ECS be implemented in Godot?

Performance loss compared to what?

The underlying ECS would typically be sparse.

Using regular ECS knowledge except for query that should all use the same underlying materialization.

So in my ECS I used hibitsets for that.

Component presence is encoded in a hibitset

Being a children of an entity is encoded in a hibitset

Change tracking is (mostly) encoded in a hibitset

What do you mean ? About which performance loss ??

Performance loss compared to what?

Performance loss compared to a sparse set ECS

The sceneTree traversal more or less has the same as querying.

Emi addressed ECS in a recent Godot Tomorrow. He says they are planning on supporting it in 4.7, which is already in dev release. Your time might be better spent heading over to the dev rocket chat and giving help and feedback on that before it is released.

Ok and how do I access it ?

…and scroll to the bottom, or: https://chat.godotengine.org/

What does that meah? How is the range of functionalities that is currently delegated to nodes implemented in this system?

This mean the ECS would emphasize structural changes instead of raw performance.

This make it easier to model the sceneTree.

Ideally, most functionnalities that work with the sceneTree (add child, reparent, queue free, etc) are doable.

The only limit I see now for functionnality is children order…

In my proposition, childrens of a node would have a random order and it would be hard to change the place of a child.

Those are not node functionalities. I meant the things that nodes are doing, like drawing geometry, detecting collisions, playing sounds. Who does that in your system?

Oh :roll_eyes:

Those are thing regular ECS systems would handle.

They will query entities relevant to their work and do the job. This how any ECS work.

That’s why I talked about abstract filtering.

Those systems would not only be able to query for components but also things like “being a child of x”

Hey, I’m not sure how you got this, but I said actually quite the opposite. We are not going to be adding ECS to Godot and what I was recommending people during the stream was to use another engine instead if you really wanted to do that. Do you have a timestamp where I mentioned that we were going to be adding this in 4.7? I want to make sure I didn’t miss spoke or how to improve my communication in the future :sweat_smile:

3 Likes

Smart choice.

Ha! You’re right! I think I conflated what you were saying about traits with that. Apologies for the confusion. It wasn’t you. It was 100% me.

The only thing that would help would be posting the links in thread again, because I was playing catch-up and watched 3 in one day. Ha.

Welp :stuck_out_tongue:

At least I tried.

I thought it would be an interesting way to improve Godot.

But I understand, it would mean a massive refactor and change.

If you really want to go this route you should check engines such as Bevy which are already designed to accommodate for this: https://bevy.org/

2 Likes

I know bevy… and I totally don’t feel that engine :slight_smile:

Yeah it’s cool engine but they already have an ECS (that is not that great)

1 Like