Skip to content

Commit b15a13e

Browse files
committed
Merge pull request #112607 from KoBeWi/what_could_have_gone_wrong🤷‍♂️
Add MeshInstance3D upgrade code
2 parents c0a397f + 251746a commit b15a13e

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

core/config/project_settings.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,21 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path,
989989
// Fallback to text-based project.godot file if binary was not found.
990990
err = _load_settings_text(p_text_path);
991991
if (err == OK) {
992+
#ifndef DISABLE_DEPRECATED
993+
const PackedStringArray features = get_setting("application/config/features");
994+
for (const String &feat : features) {
995+
if (feat.contains_char('.') && feat.get_slice_count(".") == 2) {
996+
int major_version = feat.get_slicec('.', 0).to_int();
997+
int minor_version = feat.get_slicec('.', 1).to_int();
998+
// Major version is irrelevant, but the extra check ensures that the feature is in fact a version string.
999+
if (major_version == 4 && minor_version < 6) {
1000+
// Enable MeshInstance3D compat for projects created before 4.6.
1001+
set_setting("animation/compatibility/default_parent_skeleton_in_mesh_instance_3d", true);
1002+
}
1003+
break;
1004+
}
1005+
}
1006+
#endif
9921007
return OK;
9931008
} else if (err != ERR_FILE_NOT_FOUND) {
9941009
ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err));

doc/classes/ProjectSettings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
</member>
285285
<member name="animation/compatibility/default_parent_skeleton_in_mesh_instance_3d" type="bool" setter="" getter="" default="false">
286286
If [code]true[/code], [member MeshInstance3D.skeleton] will point to the parent node ([code]..[/code]) by default, which was the behavior before Godot 4.6. It's recommended to keep this setting disabled unless the old behavior is needed for compatibility.
287+
[b]Note:[/b] If you disable this option in an existing project, it's strongly recommended to use the [code]Project &gt; Tools &gt; Upgrade Project Files...[/code] option to ensure existing scenes do not break.
287288
</member>
288289
<member name="animation/warnings/check_angle_interpolation_type_conflicting" type="bool" setter="" getter="" default="true">
289290
If [code]true[/code], [AnimationMixer] prints the warning of interpolation being forced to choose the shortest rotation path due to multiple angle interpolation types being mixed in the [AnimationMixer] cache.

editor/project_upgrade/project_upgrade_tool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030

3131
#include "project_upgrade_tool.h"
3232

33+
#include "core/config/project_settings.h"
3334
#include "core/io/dir_access.h"
3435
#include "editor/editor_node.h"
3536
#include "editor/file_system/editor_file_system.h"
3637
#include "editor/scene/editor_scene_tabs.h"
3738
#include "editor/settings/editor_settings.h"
3839
#include "editor/themes/editor_scale.h"
40+
#include "scene/3d/mesh_instance_3d.h"
3941
#include "scene/gui/dialogs.h"
4042

4143
void ProjectUpgradeTool::_add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_scenes, Vector<String> &r_resave_resources) {
@@ -77,6 +79,9 @@ void ProjectUpgradeTool::popup_dialog() {
7779
void ProjectUpgradeTool::prepare_upgrade() {
7880
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RUN_ON_RESTART, true);
7981

82+
ProjectSettings::get_singleton()->set_setting("animation/compatibility/default_parent_skeleton_in_mesh_instance_3d", false);
83+
ProjectSettings::get_singleton()->save();
84+
8085
Vector<String> reimport_paths;
8186
Vector<String> resave_scenes;
8287
Vector<String> resave_resources;
@@ -102,6 +107,7 @@ void ProjectUpgradeTool::finish_upgrade() {
102107
EditorFileSystem::get_singleton()->reimport_files(paths);
103108
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, Variant());
104109

110+
MeshInstance3D::upgrading_skeleton_compat = true;
105111
{
106112
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Vector<String>());
107113
EditorProgress ep("uid_upgrade_resave", TTR("Updating Project Scenes"), paths.size());
@@ -115,6 +121,7 @@ void ProjectUpgradeTool::finish_upgrade() {
115121
}
116122
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Variant());
117123
}
124+
MeshInstance3D::upgrading_skeleton_compat = false;
118125

119126
{
120127
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, Vector<String>());

scene/3d/mesh_instance_3d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ void MeshInstance3D::create_multiple_convex_collisions(const Ref<MeshConvexDecom
342342
void MeshInstance3D::_notification(int p_what) {
343343
switch (p_what) {
344344
case NOTIFICATION_ENTER_TREE: {
345+
#ifndef DISABLE_DEPRECATED
346+
if (upgrading_skeleton_compat) {
347+
if (skeleton_path.is_empty() && Object::cast_to<Skeleton3D>(get_parent())) {
348+
skeleton_path = NodePath("..");
349+
}
350+
}
351+
#endif
345352
_resolve_skeleton_path();
346353
} break;
347354
case NOTIFICATION_TRANSLATION_CHANGED: {

scene/3d/mesh_instance_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class MeshInstance3D : public GeometryInstance3D {
7575

7676
#ifndef DISABLE_DEPRECATED
7777
static inline bool use_parent_skeleton_compat = false;
78+
static inline bool upgrading_skeleton_compat = false;
7879
#endif
7980

8081
void set_mesh(const Ref<Mesh> &p_mesh);

0 commit comments

Comments
 (0)