diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 5c99ed7de56..1fd78544f44 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -277,7 +277,27 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc Vector2 q = ((p_point - dst_rect.position) / dst_rect.size) * src_rect.size + src_rect.position; - Ref image = texture->get_data(); + Ref image; + Ref atlasTexture = texture; + if (atlasTexture.is_null()) { + image = texture->get_data(); + } else { + ERR_FAIL_COND_V(atlasTexture->get_atlas().is_null(), false); + + image = atlasTexture->get_atlas()->get_data(); + + Rect2 region = atlasTexture->get_region(); + Rect2 margin = atlasTexture->get_margin(); + + q -= margin.position; + + if ((q.x > region.size.width) || (q.y > region.size.height)) { + return false; + } + + q += region.position; + } + ERR_FAIL_COND_V(image.is_null(), false); image->lock();