Skip to content

Commit cf165a1

Browse files
committed
Merge pull request godotengine#99739 from ydeltastar/fix-default-environment
Fix default `Environment` project setting and loading
2 parents 05e93a6 + 8793764 commit cf165a1

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

scene/main/scene_tree.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -608,25 +608,38 @@ bool SceneTree::process(double p_time) {
608608
#ifdef TOOLS_ENABLED
609609
#ifndef _3D_DISABLED
610610
if (Engine::get_singleton()->is_editor_hint()) {
611-
//simple hack to reload fallback environment if it changed from editor
612611
String env_path = GLOBAL_GET(SNAME("rendering/environment/defaults/default_environment"));
613-
env_path = env_path.strip_edges(); //user may have added a space or two
614-
String cpath;
615-
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
616-
if (fallback.is_valid()) {
617-
cpath = fallback->get_path();
612+
env_path = env_path.strip_edges(); // User may have added a space or two.
613+
614+
bool can_load = true;
615+
if (env_path.begins_with("uid://")) {
616+
// If an uid path, ensure it is mapped to a resource which could not be
617+
// the case if the editor is still scanning the filesystem.
618+
ResourceUID::ID id = ResourceUID::get_singleton()->text_to_id(env_path);
619+
can_load = ResourceUID::get_singleton()->has_id(id);
620+
if (can_load) {
621+
env_path = ResourceUID::get_singleton()->get_id_path(id);
622+
}
618623
}
619-
if (cpath != env_path) {
620-
if (!env_path.is_empty()) {
621-
fallback = ResourceLoader::load(env_path);
622-
if (fallback.is_null()) {
623-
//could not load fallback, set as empty
624-
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");
624+
625+
if (can_load) {
626+
String cpath;
627+
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
628+
if (fallback.is_valid()) {
629+
cpath = fallback->get_path();
630+
}
631+
if (cpath != env_path) {
632+
if (!env_path.is_empty()) {
633+
fallback = ResourceLoader::load(env_path);
634+
if (fallback.is_null()) {
635+
//could not load fallback, set as empty
636+
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");
637+
}
638+
} else {
639+
fallback.unref();
625640
}
626-
} else {
627-
fallback.unref();
641+
get_root()->get_world_3d()->set_fallback_environment(fallback);
628642
}
629-
get_root()->get_world_3d()->set_fallback_environment(fallback);
630643
}
631644
}
632645
#endif // _3D_DISABLED

0 commit comments

Comments
 (0)