Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default Environment project setting and loading #99739

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,25 +608,38 @@ bool SceneTree::process(double p_time) {
#ifdef TOOLS_ENABLED
#ifndef _3D_DISABLED
if (Engine::get_singleton()->is_editor_hint()) {
//simple hack to reload fallback environment if it changed from editor
String env_path = GLOBAL_GET(SNAME("rendering/environment/defaults/default_environment"));
env_path = env_path.strip_edges(); //user may have added a space or two
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
if (fallback.is_valid()) {
cpath = fallback->get_path();
env_path = env_path.strip_edges(); // User may have added a space or two.

bool can_load = true;
if (env_path.begins_with("uid://")) {
// If an uid path, ensure it is mapped to a resource which could not be
// the case if the editor is still scanning the filesystem.
ResourceUID::ID id = ResourceUID::get_singleton()->text_to_id(env_path);
can_load = ResourceUID::get_singleton()->has_id(id);
if (can_load) {
env_path = ResourceUID::get_singleton()->get_id_path(id);
}
}
if (cpath != env_path) {
if (!env_path.is_empty()) {
fallback = ResourceLoader::load(env_path);
if (fallback.is_null()) {
//could not load fallback, set as empty
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");

if (can_load) {
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
if (fallback.is_valid()) {
cpath = fallback->get_path();
}
if (cpath != env_path) {
if (!env_path.is_empty()) {
fallback = ResourceLoader::load(env_path);
if (fallback.is_null()) {
//could not load fallback, set as empty
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");
}
} else {
fallback.unref();
}
} else {
fallback.unref();
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
}
#endif // _3D_DISABLED
Expand Down