Merge pull request #99739 from ydeltastar/fix-default-environment

Fix default `Environment` project setting and loading
This commit is contained in:
Rémi Verschelde 2024-11-29 22:51:14 +01:00
commit cf165a1d29
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -608,9 +608,21 @@ 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
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 (can_load) {
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
if (fallback.is_valid()) {
@ -629,6 +641,7 @@ bool SceneTree::process(double p_time) {
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
}
}
#endif // _3D_DISABLED
#endif // TOOLS_ENABLED