Repository: godotengine/godot
File: editor/import/3d/resource_importer_scene.cpp (C++)

Code before:
Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, HashSet<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps, float p_applied_root_scale) {
	// children first
	for (int i = 0; i < p_node->get_child_count(); i++) {
		Node *r = _post_fix_node(p_node->get_child(i), p_root, collision_map, r_occluder_arrays, r_scanned_meshes, p_node_data, p_material_data, p_animation_data, p_animation_fps, p_applied_root_scale);
		if (!r) {
			i--; //was erased
		}
	}

	bool isroot = p_node == p_root;

	String import_id = p_node->get_meta("import_id", "PATH:" + p_root->get_path_to(p_node));

	Dictionary node_settings;
	if (p_node_data.has(import_id)) {
		node_settings = p_node_data[import_id];
	}

	if (!isroot && (node_settings.has("import/skip_import") && bool(node_settings["import/skip_import"]))) {
		p_node->set_owner(nullptr);
		memdelete(p_node);
		return nullptr;
	}

	{
		//make sure this is unique
		node_settings = node_settings.duplicate(true);
		//fill node settings for this node with default values
		List<ImportOption> iopts;
		if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
			get_internal_import_options(INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE, &iopts);
		} else if (Object::cast_to<AnimationPlayer>(p_node)) {
			get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, &iopts);
		} else if (Object::cast_to<Skeleton3D>(p_node)) {
			get_internal_import_options(INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE, &iopts);
		} else {
			get_internal_import_options(INTERNAL_IMPORT_CATEGORY_NODE, &iopts);
		}
		for (const ImportOption &E : iopts) {
			if (!node_settings.has(E.option.name)) {
				node_settings[E.option.name] = E.default_value;
			}
		}
	}

	{
		ObjectID node_id = p_node->get_instance_id();
		for (int i = 0; i < post_importer_plugins.size(); i++) {
			post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_NODE, p_root, p_node, Ref<Resource>(), node_settings);
			if (ObjectDB::get_instance(node_id) == nullptr) { //may have been erased, so do not continue
				break;

Review comment (suggestion):
```suggestion
				if (rest_animation.is_null()) {
```

Code after:

	if (Object::cast_to<Skeleton3D>(p_node)) {
		Ref<Animation> rest_animation;
		float rest_animation_timestamp = 0.0;
		Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);
		if (skeleton != nullptr && int(node_settings.get("rest_pose/load_pose", 0)) != 0) {
			String selected_animation_name = node_settings.get("rest_pose/selected_animation", String());
			if (int(node_settings["rest_pose/load_pose"]) == 1) {
				TypedArray<Node> children = p_root->find_children("*", "AnimationPlayer", true, false);
				for (int node_i = 0; node_i < children.size(); node_i++) {
					AnimationPlayer *anim_player = cast_to<AnimationPlayer>(children[node_i]);
					ERR_CONTINUE(anim_player == nullptr);
					List<StringName> anim_list;
					anim_player->get_animation_list(&anim_list);
					if (anim_list.size() == 1) {
						selected_animation_name = anim_list[0];
					}
					rest_animation = anim_player->get_animation(selected_animation_name);
					if (rest_animation.is_valid()) {
						break;
					}
				}
			} else if (int(node_settings["rest_pose/load_pose"]) == 2) {
				Object *external_object = node_settings.get("rest_pose/external_animation_library", Variant());
				rest_animation = external_object;
				if (rest_animation.is_null()) {
					Ref<AnimationLibrary> library(external_object);
					if (library.is_valid()) {
						List<StringName> anim_list;
						library->get_animation_list(&anim_list);
						if (anim_list.size() == 1) {
							selected_animation_name = String(anim_list[0]);
						}
						rest_animation = library->get_animation(selected_animation_name);
					}
				}
			}
			rest_animation_timestamp = double(node_settings.get("rest_pose/selected_timestamp", 0.0));
			if (rest_animation.is_valid()) {
				for (int track_i = 0; track_i < rest_animation->get_track_count(); track_i++) {
					NodePath path = rest_animation->track_get_path(track_i);
					StringName node_path = path.get_concatenated_names();
					if (String(node_path).begins_with("%")) {
						continue; // Unique node names are commonly used with retargeted animations, which we do not want to use.
					}
					StringName skeleton_bone = path.get_concatenated_subnames();
					if (skeleton_bone == StringName()) {
						continue;
					}
					int bone_idx = skeleton->find_bone(skeleton_bone);
					if (bone_idx == -1) {