Skip to content

Commit 0a056c7

Browse files
Revert "Entity path methods and bsn entity path resolving (#24018)" (#24034)
This reverts commit 98c6910. # Objective @cart's [objections](https://discord.com/channels/691052431525675048/749335865876021248/1499119335828881529): 1. I'm not sure top-level World methods for path-driven access is justifiable in its current form. For anything but the smallest application, looping over every Name in the app to find the one you're looking for is pretty much never what you want 2. Calling Name::to_string() and collecting the result in a Vec isn't going to cut it performance wise. Even within the scoped context of entity access we shouldn't be doing any allocations or "recomputations". Just the act of comparison across all entities is arguably too expensive ## Solution Revert it for now and go back to revising the work before landing it. ## Plan going forward [Core plan](https://discord.com/channels/691052431525675048/749335865876021248/1499120012034838692): 1. An EntityRef API that is always relative to the current entity 2. Grab the Children component. 3. Iterate over it, read the Name on each component, see if it matches the current piece of the path. 4. Add docs discouraging usage in most cases; users should prefer `EntityTemplate` and pre-resolved connections. As discussed [here](https://discord.com/channels/691052431525675048/749335865876021248/1499120218927271987), opt-in names indexing (both all names for inspector use cases and based on With filters for e.g. animation) should be considered too, but doesn't need to be in the MVP. @laundmo suggests the use of a trie, while Sander says that a hashmap is adequate in flecs.
1 parent 98c6910 commit 0a056c7

5 files changed

Lines changed: 7 additions & 533 deletions

File tree

_release-content/release-notes/entity_path_resolving.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

crates/bevy_ecs/src/template.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
resource::Resource,
99
world::{EntityWorldMut, Mut, World},
1010
};
11-
use alloc::{string::String, vec, vec::Vec};
11+
use alloc::{vec, vec::Vec};
1212
use variadics_please::all_tuples;
1313

1414
/// A [`Template`] is something that, given a spawn context (target [`Entity`], [`World`], etc), can produce a [`Template::Output`].
@@ -405,8 +405,6 @@ pub trait SpecializeFromTemplate: Sized {}
405405
pub enum EntityTemplate {
406406
/// A reference to a specific [`Entity`]
407407
Entity(Entity),
408-
/// A path to a specific [`Entity`]. Resolved via [`World::get_entity_from_path::<ChildOf, Name>`]
409-
EntityPath(String),
410408
/// A reference to an entity via a [`ScopedEntityIndex`]
411409
ScopedEntityIndex(ScopedEntityIndex),
412410
}
@@ -437,25 +435,12 @@ impl From<Entity> for EntityTemplate {
437435
}
438436
}
439437

440-
impl From<String> for EntityTemplate {
441-
fn from(path: String) -> Self {
442-
Self::EntityPath(path)
443-
}
444-
}
445-
446-
impl From<&'static str> for EntityTemplate {
447-
fn from(path: &'static str) -> Self {
448-
Self::EntityPath(path.into())
449-
}
450-
}
451-
452438
impl Template for EntityTemplate {
453439
type Output = Entity;
454440

455441
fn build_template(&self, context: &mut TemplateContext) -> Result<Self::Output> {
456442
Ok(match self {
457443
Self::Entity(entity) => *entity,
458-
Self::EntityPath(path) => context.entity.world().get_entity_from_path(path, None)?,
459444
Self::ScopedEntityIndex(scoped_entity_index) => {
460445
context.get_scoped_entity(*scoped_entity_index)
461446
}
@@ -465,7 +450,6 @@ impl Template for EntityTemplate {
465450
fn clone_template(&self) -> Self {
466451
match self {
467452
Self::Entity(entity) => Self::Entity(*entity),
468-
Self::EntityPath(path) => Self::EntityPath(path.clone()),
469453
Self::ScopedEntityIndex(scoped_entity_index) => {
470454
Self::ScopedEntityIndex(*scoped_entity_index)
471455
}

crates/bevy_ecs/src/world/error.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains error types returned by bevy's schedule.
22
3-
use alloc::{string::String, vec::Vec};
3+
use alloc::vec::Vec;
44
use bevy_utils::prelude::DebugName;
55

66
use crate::{
@@ -75,26 +75,6 @@ pub enum ResourceFetchError {
7575
NoResourceAccess(ComponentId),
7676
}
7777

78-
/// An error returned when a path cannot be resolved.
79-
#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
80-
pub enum EntityPathError {
81-
/// Path is empty
82-
#[error("Entity path is empty")]
83-
EmptyPath,
84-
/// Root entity is not an ancestor of the starting entity
85-
#[error("{0} is not an ancestor of {1}")]
86-
RootIsNotAncestor(Entity, Entity),
87-
/// One of the entities along the path does not contain a `Name` component
88-
#[error("{0}, or one of it's ancestors does not contain a `Name` component")]
89-
BrokenPath(Entity),
90-
/// No paths match the given path
91-
#[error("{0} does not match any entity")]
92-
NoMatchingPath(String),
93-
/// More than one paths match the given path
94-
#[error("{0} matches multiple entities")]
95-
AmbiguousPath(String),
96-
}
97-
9878
#[cfg(test)]
9979
mod tests {
10080
use crate::{

0 commit comments

Comments
 (0)