godotengine / godotengine/godot
Regression? FileAccess will load files next to binary when not found in pck using res:// path
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Tested - v4.5.stable.official [876b29033]
Tested - v4.4.stable.official [4c311cbee]
### System information
Godot v4.5.stable - Windows 10 (build 19045) - Single-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 32.0.15.7688) - Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz (16 threads) - 31.92 GiB memory
### Issue description
I believe that there is a regression in how file paths are handled. Specifically:
**How I have understood it to work previously:**
When using FileAccess to open a file at "res://test.txt", the file must be present in the PCK. The "res://" path will specifically force Godot to only look inside the PCK/Project. And an exported project will **not** load files that are actually outside the PCK, where they are actually at "./test.txt"
**How it appears to work now:**
Supposing the following file structure:
```
Folder
- game.exe
- game.pck <- Does not container text.txt
- text.txt
```
**What I think should happen:**
`FileAccess.open("res://text.txt") == FILE_NOT_FOUND`
`FileAccess.open("./text.txt") == OK` <- Fails to find in PCK first, then falls back to relative.
`FileAccess.open(ProjectSettings.globalize_path("res://text.txt")) == OK` <- Only checks relative, never PCK
**What does happen:**
`FileAccess.open("res://text.txt") == OK`
`FileAccess.open("./text.txt") == OK` <- No change.
`FileAccess.open(ProjectSettings.globalize_path("res://text.txt")) == OK` <- Now works like "./"
### I'd like a sanity check on this, because there appears to be no documentation on whether or not res:// >should or should not< allow loading external files.
If this is intentional, I'd say we make a documentation issue instead of this. Though I'd object to that being how it should work. ¯\_(ツ)_/¯
### Steps to reproduce
Refer to the examples / MRP.
### Minimal reproduction project (MRP)
[res_path_error_test.zip](https://github.com/user-attachments/files/22659847/res_path_error_test.zip)
This project is made in Godot 4.5, but it will run without changes in 4.4. Make sure to exclude test_resource.tres in the export, so that it will not be included in the .pck.
**Output in 4.5:**
As a tool, or from the editor, or exported, all three will result in the same outcome:
```
FILE TEST
PACK result = 0
RELATIVE result = 0
GLOBALIZED result = 0
RESOURCE TEST
PACK result =
RELATIVE result =
GLOBALIZED result =
```
Expected behavior: Both PACK results fail to open/load the file.
Contributor guide
Research direction
Start with the attached res_path_error_test.zip MRP and reproduce the exported-project results after excluding test_resource.tres from the PCK. Trace the FileAccess.open("res://text.txt") and ProjectSettings.globalize_path("res://text.txt") entry points, then compare their behavior with ./text.txt. Done means the intended distinction between PCK-only and external-file loading is established and the regression or documentation gap is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, godot
- Domain
- game-dev, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100