-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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 "res://" being replaced by resource packs in the editor and on Android #90425
Conversation
One alternative approach I could imagine might be preferable is to change the behavior of |
Similar problems also exist on Android, because on Android, "res://" is also a real local directory. |
Is there an issue documenting the problem on Android? I'm not sure my fix would resolve that, but I could try it out. By the way, this may go beyond the scope of a bugfix, but I think my approach could easily be adapted to allow users to load any directory on the filesystem as a "pack", not just the resource folder. This could be very useful to modders, who would otherwise need to pack all assets into a .pck or .zip file every time they want to test changes to their mod while developing it. This would work by e.g. ProjectSettings.load_resource_pack("path/to/mod/directory"). |
#87274 |
Ah yes, that does appear to be the same problem and my PR should fix it (unless there are additional complications due to Android, I'll try to test that out). Adding it to the list of relevant issues, thank you. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
I just realized there is a problem in my code: After loading a resource pack, you can only see files that existed in res:// at the time the first pack was loaded. Meaning any files that were created in the resource folder at runtime after loading the pack won't be visible. This is still better than the current behavior, where you can't see any files not belonging to datapacks in the resource folder at all, but ideally there shouldn't be any unexpected side effects to loading a resource pack. |
It feels like the current fix is the usable version, |
I tend to agree, but then the behavior of this edge case should be documented. Fact is that it is currently possible to modify |
The last thing I need clarity on is whether and how to expose
|
I don't think there is any need to expose |
Makes sense. Would you say this PR is ready to be merged as is then, or should I include a check to prevent users from accessing the new internal functionality manually from GDScript until it's fleshed out and documented later? I'm thinking of adding something like |
Reasonable, before the function is determined, user calls should indeed be prevented from producing unpredictable results. |
By doing some more tests I realized setting the argument |
As discussed earlier, I added a line to the documentation of |
I'm failing a unit test for the macOS editor. Unfortunately I don't have access to any Apple computers... does anyone have an idea for what could be causing this? I assume it might have something to do with how I'm iterating over hidden directories? |
That one happens randomly on macOS, we're still unsure why, I'll just run it again and it should fix itself |
How is the progress of this PR? Is it possible to merge in 4.3? |
It's ready from my side. Since it's a bug-fix I assume it could even be cherrypicked for 4.2.x / 4.1.x? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good to me!
Worth calling out that the touched code is not specific to Android, so an additional review from #platforms
and #core
may be needed.
I've been thinking, maybe Edit: Or |
Just a quick status update. This looks promising (and appears to solve a lot of important issues), but from a quick chat with @reduzio it seemed to us that there is a deeper design issue with the resource pack loading, which would need to be addressed properly instead of worked around like done here. So this needs further research (likely from the @godotengine/core team), which may or may not lead to merging this solution as is, or a more involved one. Either case, since we're in feature freeze for 4.3 now and this is relatively sensitive code, we'll postpone this to 4.4 (and consider a 4.3 cherry-pick if the solution we end up merging seems suitable for it). |
Understood, thank you for the update! Please let me know if there's any way I can help. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
The other issue is off topic for this PR, but the 3.6 marked issue is now not linked to this so it can be tracked and discussed, not all fixes can be applied to 3.x because of compatibility and complexity |
For what it's worth, I think my fix would easily transfer to 3.x as well. I can look into it once we have an agreed upon solution for 4.x. |
I've found an issue with this fix (because it doesn't fix something crucial). When you load a resource pack with replace files enabled, it will only replace files if they haven't been referenced before loading the pck/zip. |
adding on to this, this fix is mostly what id need, however trying to replace files using load_resource_pack is hopeless. either checking which files, resources and scenes etc are loaded before the pck gets loaded, then unloading them. or just giving us a way to see what resources are already loaded would be incredibly helpful! heck, resource loader has a mode which allows us to replace files upon loading a resource, it would be amazing if it could just reload existing resources, upon the pck file being loaded, thatd make mods SOOO much more flexible! |
Hi! It's been a while since I worked on this, but IIRC replacing files that have been previously loaded is not a trivial fix due to how the resource system works, and I think it would be out of scope for this specific PR. And as akien said earlier, the whole resource pack system has design flaws and will have to be fundamentally changed to properly fix all its various issues, so I am waiting on updates on those plans before I can build on this PR. |
@tracefree Any chance you would be able to incorporate the feedback from @bruvzg above, within the next few weeks? If not, I could take this pull request across the finish line, if that's fine with you. The issue that this PR solves has turned out to (perhaps unsurprisingly) affect the patch system introduced in #97118 as well, so it would seem to me that it's quite important that we get this fixed before 4.4-stable. |
@mihe Hi! Sorry, I got sidetracked and hadn't found the time to look into this issue once more even though I've been meaning to. Thanks for the reminder, I will look into it by this weekend at the latest! |
18bce22
to
f9dffc6
Compare
f9dffc6
to
d17ce4c
Compare
Some more thoughts in addition to my code review comment:
|
Thanks! |
Fix "res://" being replaced by resource packs in the editor and on Android
The problem
When using
ProjectSettings.load_resource_pack
and launching the game from the editor or on Android,DirAccess
no longer sees files and directories outside of loaded packs, which is unexpected behavior and makes it difficult to work on modding support for example.My solution
The simplest way I could find to solve this was to add a new kind of
PackSource
:PackedSourceDirectory
(working title).It uses a resource directory as the source of the "pack" rather than a file, and returns regular FileAccess references.
The first time a resource pack is loaded, the entire "res://" directory gets added to
PackedData
.I adapted the MRP of #48563 to Godot 4.x:
MRPResourcePack.zip
I am new to Godot's codebase and C++ in general, so there is probably a better solution. I'd be happy about any feedback or suggestions on how to solve this problem properly.
Edit: This should also solve
replace_files == false
not doing anything in non-exported projects, see #89299.ProjectSettings.load_resource_pack
replaces res:// completely #48563