From 5c831bc8d6a77bd7864075537b9c3f24a0a46de9 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Fri, 16 Oct 2020 09:33:24 +0200 Subject: [PATCH] Fix mesh instance materials not initialized correctly This fixes a regression from PR #40313 (support for software skinning in MeshInstance). Before, the base mesh was always updated on load even if not skinning was used, which caused mesh instance materials to be reset on the rendering side. Now the base mesh is set only when it has been modified, or when switching software skinning on or off. In this case the mesh instance materials are always updated properly afterwards. --- scene/3d/mesh_instance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 3d66ce5047c..29c11c54194 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -355,9 +355,9 @@ void MeshInstance::_initialize_skinning(bool p_force_reset) { } RID render_mesh = software_skinning ? software_skinning->mesh_instance->get_rid() : mesh->get_rid(); - set_base(render_mesh); + if (update_mesh || (render_mesh != get_base())) { + set_base(render_mesh); - if (update_mesh) { // Update instance materials after switching mesh. int surface_count = mesh->get_surface_count(); for (int surface_index = 0; surface_index < surface_count; ++surface_index) {