From 5e95d317e6100947f13b1b82eeb512a11f784969 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Thu, 11 Nov 2021 20:44:54 -0800 Subject: [PATCH] Update CanvasItem when MultiMesh instance transform changes (cherry picked from commit b54d4a93be231344940a2aee16ca1dbe3dc3e2b6) --- scene/2d/multimesh_instance_2d.cpp | 10 ++++++++++ scene/resources/multimesh.cpp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp index 66fc10ba058..972dce2c4d7 100644 --- a/scene/2d/multimesh_instance_2d.cpp +++ b/scene/2d/multimesh_instance_2d.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "multimesh_instance_2d.h" +#include "core/core_string_names.h" void MultiMeshInstance2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -56,7 +57,16 @@ void MultiMeshInstance2D::_bind_methods() { } void MultiMeshInstance2D::set_multimesh(const Ref &p_multimesh) { + // Cleanup previous connection if any. + if (multimesh.is_valid()) { + multimesh->disconnect(CoreStringNames::get_singleton()->changed, this, "update"); + } multimesh = p_multimesh; + + // Connect to the multimesh so the AABB can update when instance transforms are changed. + if (multimesh.is_valid()) { + multimesh->connect(CoreStringNames::get_singleton()->changed, this, "update"); + } update(); } diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index 1220cd59bc0..43c270c9f33 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "multimesh.h" + #include "servers/visual_server.h" void MultiMesh::_set_transform_array(const PoolVector &p_array) { @@ -225,6 +226,7 @@ void MultiMesh::set_instance_transform(int p_instance, const Transform &p_transf void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) { VisualServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); + emit_changed(); } Transform MultiMesh::get_instance_transform(int p_instance) const {