@@ -472,13 +472,30 @@ void ProjectSettings::_emit_changed() {
472472 emit_signal (" settings_changed" );
473473}
474474
475- bool ProjectSettings::_load_resource_pack (const String &p_pack, bool p_replace_files, int p_offset) {
475+ bool ProjectSettings::load_resource_pack (const String &p_pack, bool p_replace_files, int p_offset) {
476+ return ProjectSettings::_load_resource_pack (p_pack, p_replace_files, p_offset, false );
477+ }
478+
479+ bool ProjectSettings::_load_resource_pack (const String &p_pack, bool p_replace_files, int p_offset, bool p_main_pack) {
476480 if (PackedData::get_singleton ()->is_disabled ()) {
477481 return false ;
478482 }
479483
480- bool ok = PackedData::get_singleton ()->add_pack (p_pack, p_replace_files, p_offset) == OK;
484+ if (p_pack == " res://" ) {
485+ // Loading the resource directory as a pack source is reserved for internal use only.
486+ return false ;
487+ }
481488
489+ if (!p_main_pack && !using_datapack && !OS::get_singleton ()->get_resource_dir ().is_empty ()) {
490+ // Add the project's resource file system to PackedData so directory access keeps working when
491+ // the game is running without a main pack, like in the editor or on Android.
492+ PackedData::get_singleton ()->add_pack_source (memnew (PackedSourceDirectory));
493+ PackedData::get_singleton ()->add_pack (" res://" , false , 0 );
494+ DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
495+ using_datapack = true ;
496+ }
497+
498+ bool ok = PackedData::get_singleton ()->add_pack (p_pack, p_replace_files, p_offset) == OK;
482499 if (!ok) {
483500 return false ;
484501 }
@@ -491,9 +508,11 @@ bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_f
491508 ResourceUID::get_singleton ()->load_from_cache (false );
492509 }
493510
494- // if data.pck is found, all directory access will be from here
495- DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
496- using_datapack = true ;
511+ // If the data pack was found, all directory access will be from here.
512+ if (!using_datapack) {
513+ DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
514+ using_datapack = true ;
515+ }
497516
498517 return true ;
499518}
@@ -572,7 +591,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
572591 // Attempt with a user-defined main pack first
573592
574593 if (!p_main_pack.is_empty ()) {
575- bool ok = _load_resource_pack (p_main_pack);
594+ bool ok = _load_resource_pack (p_main_pack, false , 0 , true );
576595 ERR_FAIL_COND_V_MSG (!ok, ERR_CANT_OPEN, vformat (" Cannot open resource pack '%s'." , p_main_pack));
577596
578597 Error err = _load_settings_text_or_binary (" res://project.godot" , " res://project.binary" );
@@ -591,7 +610,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
591610 // and if so, we attempt loading it at the end.
592611
593612 // Attempt with PCK bundled into executable.
594- bool found = _load_resource_pack (exec_path);
613+ bool found = _load_resource_pack (exec_path, false , 0 , true );
595614
596615 // Attempt with exec_name.pck.
597616 // (This is the usual case when distributing a Godot game.)
@@ -607,20 +626,20 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
607626#ifdef MACOS_ENABLED
608627 if (!found) {
609628 // Attempt to load PCK from macOS .app bundle resources.
610- found = _load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_basename + " .pck" )) || _load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_filename + " .pck" ));
629+ found = _load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_basename + " .pck" ), false , 0 , true ) || _load_resource_pack (OS::get_singleton ()->get_bundle_resource_dir ().path_join (exec_filename + " .pck" ), false , 0 , true );
611630 }
612631#endif
613632
614633 if (!found) {
615634 // Try to load data pack at the location of the executable.
616635 // As mentioned above, we have two potential names to attempt.
617- found = _load_resource_pack (exec_dir.path_join (exec_basename + " .pck" )) || _load_resource_pack (exec_dir.path_join (exec_filename + " .pck" ));
636+ found = _load_resource_pack (exec_dir.path_join (exec_basename + " .pck" ), false , 0 , true ) || _load_resource_pack (exec_dir.path_join (exec_filename + " .pck" ), false , 0 , true );
618637 }
619638
620639 if (!found) {
621640 // If we couldn't find them next to the executable, we attempt
622641 // the current working directory. Same story, two tests.
623- found = _load_resource_pack (exec_basename + " .pck" ) || _load_resource_pack (exec_filename + " .pck" );
642+ found = _load_resource_pack (exec_basename + " .pck" , false , 0 , true ) || _load_resource_pack (exec_filename + " .pck" , false , 0 , true );
624643 }
625644
626645 // If we opened our package, try and load our project.
@@ -1418,7 +1437,7 @@ void ProjectSettings::_bind_methods() {
14181437 ClassDB::bind_method (D_METHOD (" localize_path" , " path" ), &ProjectSettings::localize_path);
14191438 ClassDB::bind_method (D_METHOD (" globalize_path" , " path" ), &ProjectSettings::globalize_path);
14201439 ClassDB::bind_method (D_METHOD (" save" ), &ProjectSettings::save);
1421- ClassDB::bind_method (D_METHOD (" load_resource_pack" , " pack" , " replace_files" , " offset" ), &ProjectSettings::_load_resource_pack , DEFVAL (true ), DEFVAL (0 ));
1440+ ClassDB::bind_method (D_METHOD (" load_resource_pack" , " pack" , " replace_files" , " offset" ), &ProjectSettings::load_resource_pack , DEFVAL (true ), DEFVAL (0 ));
14221441
14231442 ClassDB::bind_method (D_METHOD (" save_custom" , " file" ), &ProjectSettings::_save_custom_bnd);
14241443
0 commit comments