| 2132 | } |
| 2133 | |
| 2134 | void EditorNode::_save_scene(String p_file, int idx) { |
| 2135 | ERR_FAIL_COND_MSG(!saving_scene.is_empty() && saving_scene == p_file, "Scene saved while already being saved!"); |
| 2136 | |
| 2137 | Node *scene = editor_data.get_edited_scene_root(idx); |
| 2138 | |
| 2139 | if (!scene) { |
| 2140 | show_accept(TTR("This operation can't be done without a tree root."), TTR("OK")); |
| 2141 | return; |
| 2142 | } |
| 2143 | |
| 2144 | if (!scene->get_scene_file_path().is_empty() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) { |
| 2145 | show_accept(TTR("This scene can't be saved because there is a cyclic instance inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK")); |
| 2146 | return; |
| 2147 | } |
| 2148 | |
| 2149 | scene->propagate_notification(NOTIFICATION_EDITOR_PRE_SAVE); |
| 2150 | |
| 2151 | editor_data.apply_changes_in_editors(); |
| 2152 | save_default_environment(); |
| 2153 | List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups; |
| 2154 | _reset_animation_mixers(scene, &anim_backups); |
| 2155 | _save_editor_states(p_file, idx); |
| 2156 | |
| 2157 | Ref<PackedScene> sdata; |
| 2158 | |
| 2159 | if (ResourceCache::has(p_file)) { |
| 2160 | // Something may be referencing this resource and we are good with that. |
| 2161 | // We must update it, but also let the previous scene state go, as |
| 2162 | // old version still work for referencing changes in instantiated or inherited scenes. |
| 2163 | |
| 2164 | sdata = ResourceCache::get_ref(p_file); |
| 2165 | if (sdata.is_valid()) { |
| 2166 | sdata->recreate_state(); |
| 2167 | } else { |
| 2168 | sdata.instantiate(); |
| 2169 | } |
| 2170 | } else { |
| 2171 | sdata.instantiate(); |
| 2172 | } |
| 2173 | Error err = sdata->pack(scene); |
| 2174 | |
| 2175 | if (err != OK) { |
| 2176 | show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK")); |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | int flg = 0; |
| 2181 | if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) { |
| 2182 | flg |= ResourceSaver::FLAG_COMPRESS; |
| 2183 | } |
| 2184 | flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; |
| 2185 | |
| 2186 | err = ResourceSaver::save(sdata, p_file, flg); |
| 2187 | |
| 2188 | // This needs to be emitted before saving external resources. |
| 2189 | emit_signal(SNAME("scene_saved"), p_file); |
| 2190 | editor_data.notify_scene_saved(p_file); |
| 2191 |
nothing calls this directly
no test coverage detected