Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add ability to inspect entity's components #5136

Closed
wants to merge 7 commits into from

Conversation

harudagondi
Copy link
Member

@harudagondi harudagondi commented Jun 29, 2022

Objective

Solution

  • Add World::inspect_entity. It accepts an Entity and returns a vector of &ComponentInfo that the entity has.
  • Add EntityCommands::log_components. It logs the component names of the entity. (info level)

Changelog

Added

  • Ability to inspect components of an entity through World::inspect_entity or EntityCommands::log_components

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events A-Diagnostics Logging, crash handling, error reporting and performance analysis C-Usability A simple quality-of-life change that makes Bevy easier to use labels Jun 29, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first instinct was "why isn't this a Debug implementation on Entity". But of course, that won't work: Entity is just a raw identifier.

This is quite nice, but I would actually also like Components::inspect_entity, which will make this trivial to do in the middle of systems without blocking parallelization, as you can fetch &Components as a system parameter.

Once that's done I'll have a few suggestions on docs; in particular I think that we'll want to demonstrate that functionality.

Copy link
Contributor

@Nilirad Nilirad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice feature :)

The changes look ok. Once DebugEntity gets documented this should be ready to be merged.
See if you can optimize the World::inspect_entity method. I would not define it a hard requirement, but it could significantly speed up the execution.

Thanks 😃

crates/bevy_ecs/src/world/mod.rs Outdated Show resolved Hide resolved
@harudagondi
Copy link
Member Author

This is quite nice, but I would actually also like Components::inspect_entity, which will make this trivial to do in the middle of systems without blocking parallelization, as you can fetch &Components as a system parameter.

Curious, how would this implementation looks like? I imagine Components would need access to &Entities and &Archetypes, considering the current code.

@alice-i-cecile
Copy link
Member

Oh I see; this is less trivial than I expected. I'm happy with this now then.

@mockersf
Copy link
Member

This new commands can be called by commands.debug_entity(entity);. I would prefer to have it on EntityCommands rather than Commands. Something like commands.entity(entity).log_components().

Also, as it's in debug which is disabled by default, could you add to the doc comment how to enable those logs? (Setting log level for bevy_ecs to debug, no need to set everything to debug as that can be quite verbose).

As is, this log looks like this:

DEBUG bevy_ecs::system::commands: Entity 296v0: [ComponentInfo { id: ComponentId(104), descriptor: ComponentDescriptor { name: "bevy_transform::components::transform::Transform", storage_type: Table, is_send_and_sync: true, type_id: Some(TypeId { t: 15007708816768463165 }), layout: Layout { size_: 48, align_: 16 } } }, ComponentInfo { id: ComponentId(105), descriptor: ComponentDescriptor { name: "bevy_transform::components::global_transform::GlobalTransform", storage_type: Table, is_send_and_sync: true, type_id: Some(TypeId { t: 6698435399761132752 }), layout: Layout { size_: 48, align_: 16 } } }, ComponentInfo { id: ComponentId(107), descriptor: ComponentDescriptor { name: "bevy_hierarchy::components::children::Children", storage_type: Table, is_send_and_sync: true, type_id: Some(TypeId { t: 6534400962876433277 }), layout: Layout { size_: 72, align_: 8 } } }, ComponentInfo { id: ComponentId(112), descriptor: ComponentDescriptor { name: "bevy_asset::handle::Handle<bevy_scene::scene::Scene>", storage_type: Table, is_send_and_sync: true, type_id: Some(TypeId { t: 15523215543965525771 }), layout: Layout { size_: 48, align_: 8 } } }, ComponentInfo { id: ComponentId(113), descriptor: ComponentDescriptor { name: "bevy_scene::bundle::SceneInstance", storage_type: Table, is_send_and_sync: true, type_id: Some(TypeId { t: 17189814344232494045 }), layout: Layout { size_: 16, align_: 1 } } }]

I'm not sure all those info are very useful, could that be simplified?

@Nilirad
Copy link
Contributor

Nilirad commented Jun 29, 2022

it's in debug

I wonder if it should be info level instead 🤔. After all, the function is explicitly called by the user and it should work by default, without tweaking the log levels.

@alice-i-cecile
Copy link
Member

So, to summarize the requested changes:

  1. Simplify the log output. I would probably just show the name of each component.
  2. Make the command a method on EntityCommands instead.
  3. Change the log level to info!

- Simplified log output to show only the name.
- moved the function to `EntityCommands`
- change log level to INFO
@alice-i-cecile
Copy link
Member

Changes look good. I would still like to see less information in the debug logs, but I won't block on that.

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 30, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Jun 30, 2022
# Objective

- Provide a way to see the components of an entity.
- Fixes #1467

## Solution

- Add `World::inspect_entity`. It accepts an `Entity` and returns a vector of `&ComponentInfo` that the entity has.
- Add `EntityCommands::log_components`. It logs the component names of the entity. (info level)

---

## Changelog

### Added
- Ability to inspect components of an entity through `World::inspect_entity` or `EntityCommands::log_components`
@bors bors bot changed the title Add ability to inspect entity's components [Merged by Bors] - Add ability to inspect entity's components Jun 30, 2022
@bors bors bot closed this Jun 30, 2022
inodentry pushed a commit to IyesGames/bevy that referenced this pull request Aug 8, 2022
# Objective

- Provide a way to see the components of an entity.
- Fixes bevyengine#1467

## Solution

- Add `World::inspect_entity`. It accepts an `Entity` and returns a vector of `&ComponentInfo` that the entity has.
- Add `EntityCommands::log_components`. It logs the component names of the entity. (info level)

---

## Changelog

### Added
- Ability to inspect components of an entity through `World::inspect_entity` or `EntityCommands::log_components`
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

- Provide a way to see the components of an entity.
- Fixes bevyengine#1467

## Solution

- Add `World::inspect_entity`. It accepts an `Entity` and returns a vector of `&ComponentInfo` that the entity has.
- Add `EntityCommands::log_components`. It logs the component names of the entity. (info level)

---

## Changelog

### Added
- Ability to inspect components of an entity through `World::inspect_entity` or `EntityCommands::log_components`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Provide a way to see the components of an entity.
- Fixes bevyengine#1467

## Solution

- Add `World::inspect_entity`. It accepts an `Entity` and returns a vector of `&ComponentInfo` that the entity has.
- Add `EntityCommands::log_components`. It logs the component names of the entity. (info level)

---

## Changelog

### Added
- Ability to inspect components of an entity through `World::inspect_entity` or `EntityCommands::log_components`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add inspect command for debugging entities and their components
4 participants