Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,10 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
/// #[relationship(relationship_target = PeopleILike, allow_self)]
/// pub struct LikedBy(pub Entity);
/// ```
/// **Warning:** When `allow_self` is enabled, be careful when using recursive traversal methods
/// like `iter_ancestors` or `root_ancestor`, as they may loop infinitely if an entity points to itself.
/// ## Warning
///
/// When `allow_self` is enabled, be careful when using recursive traversal methods
/// like `iter_ancestors` or `root_ancestor`, as they will loop infinitely if an entity points to itself.
///
/// ## Hooks
/// ```ignore
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/relationship/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub trait Relationship: Component + Sized {
/// # Warning
///
/// When `ALLOW_SELF` is `true`, be careful when using recursive traversal methods
/// like `iter_ancestors` or `root_ancestor`, as they may loop infinitely if an entity
/// like `iter_ancestors` or `root_ancestor`, as they will loop infinitely if an entity
/// points to itself.
const ALLOW_SELF: bool = false;

Expand Down Expand Up @@ -150,7 +150,7 @@ pub trait Relationship: Component + Sized {
let target_entity = world.entity(entity).get::<Self>().unwrap().get();
if !Self::ALLOW_SELF && target_entity == entity {
warn!(
"{}The {}({target_entity:?}) relationship on entity {entity:?} points to itself. The invalid {} relationship has been removed.",
"{}The {}({target_entity:?}) relationship on entity {entity:?} points to itself. The invalid {} relationship has been removed.\nIf this is intended behavior self-referential relations can be enabled with the allow_self attribute: #[relationship(allow_self)]",
caller.map(|location|format!("{location}: ")).unwrap_or_default(),
DebugName::type_name::<Self>(),
DebugName::type_name::<Self>()
Expand Down