Skip to content

Commit

Permalink
Add editor check for compatible visibility layers for CanvasItem
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Jan 19, 2025
1 parent 9630d4e commit f17d9ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scene/main/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,29 @@ void CanvasItem::_notification(int p_what) {
}
}

PackedStringArray CanvasItem::get_configuration_warnings() const {
ERR_READ_THREAD_GUARD_V(PackedStringArray());
PackedStringArray warnings = Node::get_configuration_warnings();

// Check compatible visibility layer, only if not top-level and any bit is set.
CanvasItem *parent = get_parent_item();
if (parent && visibility_layer) {
uint32_t combined_layers = visibility_layer;

// Iterate over parents until non-canvas item, or node is top-level.
do {
combined_layers &= parent->visibility_layer;
parent = parent->get_parent_item();
} while (parent && combined_layers);

if (combined_layers == 0) {
warnings.push_back("CanvasItem with non-zero visibility_layer but shares no layer with parents, this node will not be visible.\nConsider matching at least one layer with all parents or setting this as top-level.");
}
}

return warnings;
}

void CanvasItem::update_draw_order() {
ERR_MAIN_THREAD_GUARD;

Expand Down Expand Up @@ -501,6 +524,7 @@ void CanvasItem::_top_level_changed() {
child->_top_level_changed_on_parent();
}
}
update_configuration_warnings();
}

void CanvasItem::_top_level_changed_on_parent() {
Expand Down Expand Up @@ -1479,6 +1503,9 @@ void CanvasItem::set_visibility_layer(uint32_t p_visibility_layer) {
ERR_THREAD_GUARD;
visibility_layer = p_visibility_layer;
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, p_visibility_layer);
// Note: Relies on that the whole tree being updated on request, if this behavior changes
// this needs to be propagated to child nodes.
update_configuration_warnings();
}

uint32_t CanvasItem::get_visibility_layer() const {
Expand Down
2 changes: 2 additions & 0 deletions scene/main/canvas_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ class CanvasItem : public Node {
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); }
#endif // DEBUG_ENABLED

PackedStringArray get_configuration_warnings() const override;

void update_draw_order();

/* VISIBILITY */
Expand Down

0 comments on commit f17d9ec

Please sign in to comment.