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

Add a warning for when the scene root node is transformed #81892

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 23 additions & 3 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ Node *SceneTreeEditor::get_scene_node() const {
return get_tree()->get_edited_scene_root();
}

PackedStringArray SceneTreeEditor::_get_node_configuration_warnings(Node *p_node) {
PackedStringArray warnings = p_node->get_configuration_warnings();
if (p_node == get_scene_node()) {
Node2D *node_2d = Object::cast_to<Node2D>(p_node);
if (node_2d) {
// Note: Warn for Node2D but not all CanvasItems, don't warn for Control nodes.
// Control nodes may have reasons to use a transformed root node like anchors.
if (!node_2d->get_transform().is_equal_approx(Transform2D())) {
warnings.append(TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform and reload the scene to remove this warning."));
}
}
Node3D *node_3d = Object::cast_to<Node3D>(p_node);
if (node_3d) {
if (!node_3d->get_transform().is_equal_approx(Transform3D())) {
warnings.append(TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform and reload the scene to remove this warning."));
}
}
}
return warnings;
}

void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
if (p_button != MouseButton::LEFT) {
return;
Expand Down Expand Up @@ -129,7 +150,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
}
undo_redo->commit_action();
} else if (p_id == BUTTON_WARNING) {
const PackedStringArray warnings = n->get_configuration_warnings();
const PackedStringArray warnings = _get_node_configuration_warnings(n);

if (warnings.is_empty()) {
return;
Expand Down Expand Up @@ -451,8 +472,7 @@ void SceneTreeEditor::_update_node(Node *p_node, TreeItem *p_item, bool p_part_o
}

if (can_rename) { // TODO Should be can edit..

const PackedStringArray warnings = p_node->get_configuration_warnings();
const PackedStringArray warnings = _get_node_configuration_warnings(p_node);
const int num_warnings = warnings.size();
if (num_warnings > 0) {
StringName warning_icon;
Expand Down
1 change: 1 addition & 0 deletions editor/gui/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class SceneTreeEditor : public Control {

void _compute_hash(Node *p_node, uint64_t &hash);
void _reset();
PackedStringArray _get_node_configuration_warnings(Node *p_node);

void _update_node_path(Node *p_node, bool p_recursive = true);
void _update_node_subtree(Node *p_node, TreeItem *p_parent, bool p_force = false);
Expand Down