Browse Source

Fix errors and warnings when loading Skeleton2D Modifications

Fixes #73247
johnsonbaugh 1 year ago
parent
commit
ef8acbde9a

+ 38 - 27
scene/2d/skeleton_2d.cpp

@@ -635,36 +635,47 @@ Bone2D *Skeleton2D::get_bone(int p_idx) {
 }
 }
 
 
 void Skeleton2D::_notification(int p_what) {
 void Skeleton2D::_notification(int p_what) {
-	if (p_what == NOTIFICATION_READY) {
-		if (bone_setup_dirty) {
-			_update_bone_setup();
-		}
-		if (transform_dirty) {
-			_update_transform();
-		}
-		request_ready();
-	}
+	switch (p_what) {
+		case NOTIFICATION_READY: {
+			if (bone_setup_dirty) {
+				_update_bone_setup();
+			}
+			if (transform_dirty) {
+				_update_transform();
+			}
+			request_ready();
+		} break;
 
 
-	if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
-		RS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform());
-	} else if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
-		if (modification_stack.is_valid()) {
-			execute_modifications(get_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_process);
-		}
-	} else if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
-		if (modification_stack.is_valid()) {
-			execute_modifications(get_physics_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_physics_process);
-		}
-	}
-#ifdef TOOLS_ENABLED
-	else if (p_what == NOTIFICATION_DRAW) {
-		if (Engine::get_singleton()->is_editor_hint()) {
+		case NOTIFICATION_TRANSFORM_CHANGED: {
+			RS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform());
+		} break;
+
+		case NOTIFICATION_INTERNAL_PROCESS: {
 			if (modification_stack.is_valid()) {
 			if (modification_stack.is_valid()) {
-				modification_stack->draw_editor_gizmos();
+				execute_modifications(get_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_process);
 			}
 			}
-		}
-	}
+		} break;
+
+		case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+			if (modification_stack.is_valid()) {
+				execute_modifications(get_physics_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_physics_process);
+			}
+		} break;
+
+		case NOTIFICATION_POST_ENTER_TREE: {
+			set_modification_stack(modification_stack);
+		} break;
+
+#ifdef TOOLS_ENABLED
+		case NOTIFICATION_DRAW: {
+			if (Engine::get_singleton()->is_editor_hint()) {
+				if (modification_stack.is_valid()) {
+					modification_stack->draw_editor_gizmos();
+				}
+			}
+		} break;
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED
+	}
 }
 }
 
 
 RID Skeleton2D::get_skeleton() const {
 RID Skeleton2D::get_skeleton() const {
@@ -692,7 +703,7 @@ void Skeleton2D::set_modification_stack(Ref<SkeletonModificationStack2D> p_stack
 		set_physics_process_internal(false);
 		set_physics_process_internal(false);
 	}
 	}
 	modification_stack = p_stack;
 	modification_stack = p_stack;
-	if (modification_stack.is_valid()) {
+	if (modification_stack.is_valid() && is_inside_tree()) {
 		modification_stack->set_skeleton(this);
 		modification_stack->set_skeleton(this);
 		modification_stack->setup();
 		modification_stack->setup();
 
 

+ 9 - 4
scene/resources/2d/skeleton/skeleton_modification_2d_ccdik.cpp

@@ -266,7 +266,9 @@ void SkeletonModification2DCCDIK::_draw_editor_gizmo() {
 
 
 void SkeletonModification2DCCDIK::update_target_cache() {
 void SkeletonModification2DCCDIK::update_target_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -287,7 +289,9 @@ void SkeletonModification2DCCDIK::update_target_cache() {
 
 
 void SkeletonModification2DCCDIK::update_tip_cache() {
 void SkeletonModification2DCCDIK::update_tip_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update tip cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update tip cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -309,7 +313,9 @@ void SkeletonModification2DCCDIK::update_tip_cache() {
 void SkeletonModification2DCCDIK::ccdik_joint_update_bone2d_cache(int p_joint_idx) {
 void SkeletonModification2DCCDIK::ccdik_joint_update_bone2d_cache(int p_joint_idx) {
 	ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update CCDIK Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update CCDIK Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -390,7 +396,6 @@ void SkeletonModification2DCCDIK::set_ccdik_joint_bone_index(int p_joint_idx, in
 			ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 			ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("Cannot verify the CCDIK joint " + itos(p_joint_idx) + " bone index for this modification...");
 		ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 	}
 	}
 
 

+ 12 - 3
scene/resources/2d/skeleton/skeleton_modification_2d_fabrik.cpp

@@ -289,13 +289,21 @@ void SkeletonModification2DFABRIK::_setup_modification(SkeletonModificationStack
 
 
 	if (stack != nullptr) {
 	if (stack != nullptr) {
 		is_setup = true;
 		is_setup = true;
+
+		if (stack->skeleton) {
+			for (int i = 0; i < fabrik_data_chain.size(); i++) {
+				fabrik_joint_update_bone2d_cache(i);
+			}
+		}
 		update_target_cache();
 		update_target_cache();
 	}
 	}
 }
 }
 
 
 void SkeletonModification2DFABRIK::update_target_cache() {
 void SkeletonModification2DFABRIK::update_target_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -317,7 +325,9 @@ void SkeletonModification2DFABRIK::update_target_cache() {
 void SkeletonModification2DFABRIK::fabrik_joint_update_bone2d_cache(int p_joint_idx) {
 void SkeletonModification2DFABRIK::fabrik_joint_update_bone2d_cache(int p_joint_idx) {
 	ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update FABRIK Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update FABRIK Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -389,7 +399,6 @@ void SkeletonModification2DFABRIK::set_fabrik_joint_bone_index(int p_joint_idx,
 			fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 			fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("Cannot verify the FABRIK joint " + itos(p_joint_idx) + " bone index for this modification...");
 		fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 	}
 	}
 
 

+ 8 - 3
scene/resources/2d/skeleton/skeleton_modification_2d_jiggle.cpp

@@ -254,6 +254,8 @@ void SkeletonModification2DJiggle::_setup_modification(SkeletonModificationStack
 					Bone2D *bone2d_node = stack->skeleton->get_bone(bone_idx);
 					Bone2D *bone2d_node = stack->skeleton->get_bone(bone_idx);
 					jiggle_data_chain.write[i].dynamic_position = bone2d_node->get_global_position();
 					jiggle_data_chain.write[i].dynamic_position = bone2d_node->get_global_position();
 				}
 				}
+
+				jiggle_joint_update_bone2d_cache(i);
 			}
 			}
 		}
 		}
 
 
@@ -263,7 +265,9 @@ void SkeletonModification2DJiggle::_setup_modification(SkeletonModificationStack
 
 
 void SkeletonModification2DJiggle::update_target_cache() {
 void SkeletonModification2DJiggle::update_target_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -285,7 +289,9 @@ void SkeletonModification2DJiggle::update_target_cache() {
 void SkeletonModification2DJiggle::jiggle_joint_update_bone2d_cache(int p_joint_idx) {
 void SkeletonModification2DJiggle::jiggle_joint_update_bone2d_cache(int p_joint_idx) {
 	ERR_FAIL_INDEX_MSG(p_joint_idx, jiggle_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	ERR_FAIL_INDEX_MSG(p_joint_idx, jiggle_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update Jiggle " + itos(p_joint_idx) + " Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update Jiggle " + itos(p_joint_idx) + " Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -425,7 +431,6 @@ void SkeletonModification2DJiggle::set_jiggle_joint_bone_index(int p_joint_idx,
 			jiggle_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 			jiggle_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("Cannot verify the Jiggle joint " + itos(p_joint_idx) + " bone index for this modification...");
 		jiggle_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 		jiggle_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
 	}
 	}
 
 

+ 6 - 3
scene/resources/2d/skeleton/skeleton_modification_2d_lookat.cpp

@@ -200,7 +200,9 @@ void SkeletonModification2DLookAt::_draw_editor_gizmo() {
 
 
 void SkeletonModification2DLookAt::update_bone2d_cache() {
 void SkeletonModification2DLookAt::update_bone2d_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -256,7 +258,6 @@ void SkeletonModification2DLookAt::set_bone_index(int p_bone_idx) {
 			bone_idx = p_bone_idx;
 			bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("Cannot verify the bone index for this modification...");
 		bone_idx = p_bone_idx;
 		bone_idx = p_bone_idx;
 	}
 	}
 
 
@@ -265,7 +266,9 @@ void SkeletonModification2DLookAt::set_bone_index(int p_bone_idx) {
 
 
 void SkeletonModification2DLookAt::update_target_cache() {
 void SkeletonModification2DLookAt::update_target_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 

+ 1 - 1
scene/resources/2d/skeleton/skeleton_modification_2d_physicalbones.cpp

@@ -153,7 +153,7 @@ void SkeletonModification2DPhysicalBones::_setup_modification(SkeletonModificati
 void SkeletonModification2DPhysicalBones::_physical_bone_update_cache(int p_joint_idx) {
 void SkeletonModification2DPhysicalBones::_physical_bone_update_cache(int p_joint_idx) {
 	ERR_FAIL_INDEX_MSG(p_joint_idx, physical_bone_chain.size(), "Cannot update PhysicalBone2D cache: joint index out of range!");
 	ERR_FAIL_INDEX_MSG(p_joint_idx, physical_bone_chain.size(), "Cannot update PhysicalBone2D cache: joint index out of range!");
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		if (!stack) {
+		if (is_setup) {
 			ERR_PRINT_ONCE("Cannot update PhysicalBone2D cache: modification is not properly setup!");
 			ERR_PRINT_ONCE("Cannot update PhysicalBone2D cache: modification is not properly setup!");
 		}
 		}
 		return;
 		return;

+ 9 - 5
scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.cpp

@@ -250,7 +250,9 @@ void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() {
 
 
 void SkeletonModification2DTwoBoneIK::update_target_cache() {
 void SkeletonModification2DTwoBoneIK::update_target_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -271,7 +273,9 @@ void SkeletonModification2DTwoBoneIK::update_target_cache() {
 
 
 void SkeletonModification2DTwoBoneIK::update_joint_one_bone2d_cache() {
 void SkeletonModification2DTwoBoneIK::update_joint_one_bone2d_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update joint one Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update joint one Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -299,7 +303,9 @@ void SkeletonModification2DTwoBoneIK::update_joint_one_bone2d_cache() {
 
 
 void SkeletonModification2DTwoBoneIK::update_joint_two_bone2d_cache() {
 void SkeletonModification2DTwoBoneIK::update_joint_two_bone2d_cache() {
 	if (!is_setup || !stack) {
 	if (!is_setup || !stack) {
-		ERR_PRINT_ONCE("Cannot update joint two Bone2D cache: modification is not properly setup!");
+		if (is_setup) {
+			ERR_PRINT_ONCE("Cannot update joint two Bone2D cache: modification is not properly setup!");
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -400,7 +406,6 @@ void SkeletonModification2DTwoBoneIK::set_joint_one_bone_idx(int p_bone_idx) {
 			joint_one_bone_idx = p_bone_idx;
 			joint_one_bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("TwoBoneIK: Cannot verify the joint bone index for joint one...");
 		joint_one_bone_idx = p_bone_idx;
 		joint_one_bone_idx = p_bone_idx;
 	}
 	}
 
 
@@ -425,7 +430,6 @@ void SkeletonModification2DTwoBoneIK::set_joint_two_bone_idx(int p_bone_idx) {
 			joint_two_bone_idx = p_bone_idx;
 			joint_two_bone_idx = p_bone_idx;
 		}
 		}
 	} else {
 	} else {
-		WARN_PRINT("TwoBoneIK: Cannot verify the joint bone index for joint two...");
 		joint_two_bone_idx = p_bone_idx;
 		joint_two_bone_idx = p_bone_idx;
 	}
 	}