[OPEN SOURCE] ECS for Babylon

We have been testing out existing ECS libraries, but found we wanted something more Babylon “native” and ended up creating bjs-ecs (published on npm)

Source is on GitHub.

Feel free to reach out if interested in collaborating :slight_smile:

-Pelle, skybox.gg

Excerpt from docs

Objectives

Provide an easy way to help structure your game logic for Babylon.js based projects using ECS.
This is (currently) more about the functionality of ECS than the performance benefits.
In short if you are looking for an ECS implementation to handle 10Ks of entities,
you may want to look elsewhere.

Sample

CodeSandbox

Initial integration with inspector

Inspector Support

11 Likes

Woot! This is excellent ! Thanks a lot!

1 Like

Really cool !!!

1 Like

Looks great. I haven’t seen anybody else using inspectableCustomProperties before.

I noticed you are making a tab and I hadn’t seen that before. If you add a custom property, you can get access to entity details (or anything in scope). Assuming the entity has same lifecycle as object (looks like it does from onDisposeObservable). Like this:

Object.defineProperty(node, 'entity-id', {
  get() {
    return entity.id;
  },
  enumerable: true,
})

node.inspectableCustomProperties.push(
{
  label: `Entity ID`,
  propertyName: "entity-id",
  type: InspectableType.String,
},
...
)

I like what you did with ??= to assign - I should do that instead of clobbering the inspectableCustomProperties array :smiley:

Super useful for debugging - cool to see that you tapped into that feature!

1 Like

TBH. first time playing with custom props for inspector :slight_smile:

I initially had Entity ID as a String, but that made it editable, will try out your approach where you mark the property readonly - thanks :pray:

Also had some issues with Options behaving weird, when 2 nodes had Options properties with same name but different set of values … should get around to filing an issue.

I already use custom properties in the Inspector. I am a big fan of tagging my meshes/nodes and using tag queries to look them up so I added Tags to the inspector.

Anyone else using tags?

https://doc.babylonjs.com/features/featuresDeepDive/tags

We actually also evaluated just using Tags for querying on Nodes, but in the end found we wanted a more full ECS system for our use case.

I do however think Tags are probably in general a bit underrated :slight_smile:

1 Like

Can’t agree more! It’s a very cool and effiicient way to look up entities on your scene.

FYI: just landed using archetypes for entity storage in v. 0.2.0.

This improves query performance by x10 in our benchmark :zap:

1 Like

[Update]
We just added filtering and type-completion to the entityEvents.on function.
This means that you will now be able to pass an array of components as a second argument, when registering your listener. So that you both get type completion in the callback, and the event handler will only be invoked for entities, which includes the components specified in the second argument.

1 Like