What problem does this solve or what need does it fill?
This program (note: look_at) appears to insert a Transform, but actually inserts a unit value because Transform::look_at doesn't return a Transform.
This results in the debug system never finding the non-existent Transform at best, and getting a default Transform if another Component that requires a Transform inserts a Default value (such as Mesh3d).
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, startup)
.add_systems(Update, debug)
.run();
}
fn debug(entities: Query<(&Name, &Transform)>) {
for (name, transform) in &entities {
if ["Parent"].contains(&name.as_str()) {
info!(?name, transform=?transform.translation);
}
}
}
fn startup(mut commands: Commands) {
commands.spawn((
Name::new("Parent"),
Transform::from_xyz(10.0, 0.0, 0.0)
.look_at(Vec3::ZERO, Vec3::Y),
));
}
What solution would you like?
- functions that accept exclusive references and return (), like
Transform::look_at, should link to versions that return Self like Transform::looking_at if applicable in the documentation
- A warning should be logged if
() is inserted as a component value, instead of just ignoring it
What alternative(s) have you considered?
The bevy linter includes a lint for this called unit_in_bundle with a very similar Transform example in the showcase. We could encourage use of the bevy linter instead.
What problem does this solve or what need does it fill?
This program (note:
look_at) appears to insert aTransform, but actually inserts a unit value becauseTransform::look_atdoesn't return aTransform.This results in the
debugsystem never finding the non-existent Transform at best, and getting a default Transform if another Component that requires a Transform inserts a Default value (such as Mesh3d).What solution would you like?
Transform::look_at, should link to versions that returnSelflikeTransform::looking_atif applicable in the documentation()is inserted as a component value, instead of just ignoring itWhat alternative(s) have you considered?
The bevy linter includes a lint for this called unit_in_bundle with a very similar Transform example in the showcase. We could encourage use of the bevy linter instead.