Skip to content

Commit 668699e

Browse files
committed
Add a Troubleshooting section to Exporting packs, patches and mods
- Mention that the pack must be loaded early enough to have an effect. - Mention load order being important. - Mention ZIP format throughout the page, as it can be used in the same way as PCK files. - Link to Run-time resource loading and saving tutorial as an alternative.
1 parent 4124f61 commit 668699e

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

tutorials/export/exporting_pcks.rst

+57-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Exporting packs, patches, and mods
66
Use cases
77
---------
88

9-
Oftentimes one would like to add functionality to one's game after it has been
9+
Oftentimes, one would like to add functionality to one's game after it has been
1010
deployed.
1111

1212
Examples of this include...
@@ -18,11 +18,11 @@ Examples of this include...
1818
These tools help developers to extend their development beyond the initial
1919
release.
2020

21-
Overview of PCK files
22-
---------------------
21+
Overview of PCK/ZIP files
22+
-------------------------
2323

2424
Godot enables this via a feature called **resource packs** (PCK files,
25-
with extension ``.pck``).
25+
with the ``.pck`` extension, or ZIP files).
2626

2727
**Advantages:**
2828

@@ -35,9 +35,9 @@ with extension ``.pck``).
3535

3636
The first part of using them involves exporting and delivering the project to
3737
players. Then, when one wants to add functionality or content later on, they
38-
just deliver the updates via PCK files to the users.
38+
just deliver the updates via PCK/ZIP files to the users.
3939

40-
PCK files usually contain, but are not limited to:
40+
PCK/ZIP files usually contain, but are not limited to:
4141

4242
- scripts
4343
- scenes
@@ -48,21 +48,35 @@ PCK files usually contain, but are not limited to:
4848
- music
4949
- any other asset suitable for import into the game
5050

51-
The PCK files can even be an entirely different Godot project, which the
51+
The PCK/ZIP files can even be an entirely different Godot project, which the
5252
original game loads in at runtime.
5353

54+
It is possible to load both PCK and ZIP files as additional packs at the same time.
55+
See :ref:`doc_exporting_projects_pck_versus_zip` for a comparison of the two formats.
56+
57+
.. seealso::
58+
59+
If you want to load loose files at runtime (not packed in a PCK or ZIP by Godot),
60+
consider using :ref:`doc_runtime_loading_and_saving` instead.
61+
This is useful for loading user-generated content that is not made with Godot,
62+
without requiring users to pack their mods into a specific file format.
63+
64+
The downside of this approach is that it's less transparent to the game logic,
65+
as it will not benefit from the same resource management as PCK/ZIP files.
66+
5467
Generating PCK files
5568
--------------------
5669

57-
In order to pack all resources of a project into a PCK file open the project
58-
and go to Project/Export and click on "Export PCK/Zip". Also make sure to have
59-
an export template selected while doing so.
70+
In order to pack all resources of a project into a PCK file, open the project
71+
and go to **Project > Export** and click on **Export PCK/ZIP**. Also, make sure
72+
to have an export preset selected while doing so.
6073

6174
.. image:: img/export_pck.webp
6275

63-
Another method would be to :ref:`export from the command line <doc_command_line_tutorial_exporting>`.
64-
If the output file ends with a PCK or ZIP file extension, then the export
65-
process will build that type of file for the chosen platform.
76+
Another method would be to :ref:`export from the command line <doc_command_line_tutorial_exporting>`
77+
with ``--export-pack``. The output file must with a ``.pck`` or ``.zip``
78+
file extension. The export process will build that type of file for the
79+
chosen platform.
6680

6781
.. note::
6882

@@ -86,19 +100,19 @@ process will build that type of file for the chosen platform.
86100
use a tool-build of the engine (for security), so it's best to keep
87101
the modding tool and game separate.
88102

89-
Opening PCK files at runtime
90-
----------------------------
103+
Opening PCK or ZIP files at runtime
104+
-----------------------------------
91105

92-
To import a PCK file, one uses the ProjectSettings singleton. The following
93-
example expects a mod.pck file in the directory of the games executable.
94-
The PCK file contains a mod_scene.tscn test scene in its root.
106+
To load a PCK or ZIP file, one uses the ProjectSettings singleton. The following
107+
example expects a ``mod.pck`` file in the directory of the game's executable.
108+
The PCK or ZIP file contains a ``mod_scene.tscn`` test scene in its root.
95109

96110
.. tabs::
97111
.. code-tab:: gdscript GDScript
98112

99113
func _your_function():
100114
# This could fail if, for example, mod.pck cannot be found.
101-
var success = ProjectSettings.load_resource_pack("res://mod.pck")
115+
var success = ProjectSettings.load_resource_pack(OS.get_executable_path().get_base_dir().path_join("mod.pck"))
102116

103117
if success:
104118
# Now one can use the assets as if they had them in the project from the start.
@@ -109,7 +123,7 @@ The PCK file contains a “mod_scene.tscn” test scene in its root.
109123
private void YourFunction()
110124
{
111125
// This could fail if, for example, mod.pck cannot be found.
112-
var success = ProjectSettings.LoadResourcePack("res://mod.pck");
126+
var success = ProjectSettings.LoadResourcePack(OS.get_executable_path().get_base_dir().path_join("mod.pck));
113127

114128
if (success)
115129
{
@@ -120,11 +134,14 @@ The PCK file contains a “mod_scene.tscn” test scene in its root.
120134

121135
.. warning::
122136

123-
By default, if you import a file with the same file path/name as one you already have in your
124-
project, the imported one will replace it. This is something to watch out for when
125-
creating DLC or mods. You can solve this problem by using a tool that isolates mods to a specific mods subfolder.
126-
However, it is also a way of creating patches for one's own game. A
127-
PCK file of this kind can fix the content of a previously loaded PCK.
137+
By default, if you import a file with the same file path/name as one you
138+
already have in your project, the imported one will replace it. This is
139+
something to watch out for when creating DLC or mods. You can solve this
140+
problem by using a tool that isolates mods to a specific mods subfolder.
141+
142+
However, it is also a way of creating patches for one's own game. A PCK/ZIP
143+
file of this kind can fix the content of a previously loaded PCK/ZIP
144+
(therefore, the order in which packs are loaded matters).
128145

129146
To opt out of this behavior, pass ``false`` as the second argument to
130147
:ref:`ProjectSettings.load_resource_pack() <class_ProjectSettings_method_load_resource_pack>`.
@@ -134,6 +151,21 @@ The PCK file contains a “mod_scene.tscn” test scene in its root.
134151
Then, before loading the resource pack, you need to load its DLL as follows:
135152
``Assembly.LoadFile("mod.dll")``
136153

154+
Troubleshooting
155+
^^^^^^^^^^^^^^^
156+
157+
If you are loading a resource pack and are not noticing any changes, it may be
158+
due to the pack being loaded too late. This is particularly the case with menu
159+
scenes that may preload other scenes using
160+
:ref:`preload() <class_@GDScript_method_preload>`. This means that loading
161+
a pack in the menu will not affect the other scene that was already preloaded.
162+
163+
To avoid this, you need to load the pack as early as possible.
164+
To do so, create a new :ref:`autoload <doc_singletons_autoload>` script and
165+
call :ref:`ProjectSettings.load_resource_pack() <class_ProjectSettings_method_load_resource_pack>`
166+
in the autoload script's ``_init()`` function, rather than ``_enter_tree()``
167+
or ``_ready()``.
168+
137169
Summary
138170
-------
139171

tutorials/export/exporting_projects.rst

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ the command:
220220
See :ref:`doc_command_line_tutorial` for more information about using Godot
221221
from the command line.
222222

223+
.. _doc_exporting_projects_pck_versus_zip:
224+
223225
PCK versus ZIP pack file formats
224226
--------------------------------
225227

0 commit comments

Comments
 (0)