SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
MIT License
5.7k stars 411 forks source link

Explorer hierarchy incomplete #1159

Closed maximegmd closed 3 months ago

maximegmd commented 3 months ago

Describe the bug Using the explorer web app, the hierarchy does not go beyond 1 level.

To Reproduce Steps to reproduce the behavior:

  1. Create three entities such that c is a child of b and b is a child of a.
  2. Open the explorer view and see that expanding a, shows b but expanding b does not show c.
SanderMertens commented 3 months ago

This seems to work:

Screenshot 2024-02-25 at 10 07 35 AM

Can you share the code in which you create the three entities?

maximegmd commented 3 months ago

Sure:

auto player = world.entity(fmt::format("Player {:x}", aConnectionId).c_str())
    .child_of(world.entity("Level"))
    .emplace<PlayerComponent>(aConnectionId, flecs::entity{}, aUsername.c_str());

auto puppet = world.entity()
        .child_of(player)
        .set<MovementComponent>({pos, rot, {}});

image image

SanderMertens commented 3 months ago

Ah, this is because the entity name contains spaces, which causes problems with queries. What you can do instead is:

copygirl commented 3 months ago

To be fair, from what I know, the issue only occurs when using expressions to build queries, similar to SQL injection. When you build queries using the query builder you can avoid the problem. Same I believe if you used the entity ID itself in the query expression. (Unsure why the explorer is not doing this.)

I've run into the same problem because I wanted to use dots in my entity names (to mirror filenames with extensions), which caused issues both with the explorer and even entity creation, as dots are used as separators by default. Thankfully Sander introduced a way to avoid tokenization.

SanderMertens commented 3 months ago

Yep, that's exactly it. Because the explorer is fully built on top of the (string based) query DSL, it is usually the first place where these problems show up.

I'm experimenting with some code that lets me use entity names with spaces since this comes up so often, may be able to check in a fix that adds support for it.

SanderMertens commented 3 months ago

I just checked in a fix. If you update to the latest Flecs commit and refresh the explorer it should work as expected!