@@ -6,7 +6,7 @@ Exporting packs, patches, and mods
6
6
Use cases
7
7
---------
8
8
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
10
10
deployed.
11
11
12
12
Examples of this include...
@@ -18,11 +18,11 @@ Examples of this include...
18
18
These tools help developers to extend their development beyond the initial
19
19
release.
20
20
21
- Overview of PCK files
22
- ---------------------
21
+ Overview of PCK/ZIP files
22
+ -------------------------
23
23
24
24
Godot enables this via a feature called **resource packs ** (PCK files,
25
- with extension ``.pck ``).
25
+ with the ``.pck `` extension, or ZIP files ).
26
26
27
27
**Advantages: **
28
28
@@ -35,9 +35,9 @@ with extension ``.pck``).
35
35
36
36
The first part of using them involves exporting and delivering the project to
37
37
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.
39
39
40
- PCK files usually contain, but are not limited to:
40
+ PCK/ZIP files usually contain, but are not limited to:
41
41
42
42
- scripts
43
43
- scenes
@@ -48,21 +48,35 @@ PCK files usually contain, but are not limited to:
48
48
- music
49
49
- any other asset suitable for import into the game
50
50
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
52
52
original game loads in at runtime.
53
53
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
+
54
67
Generating PCK files
55
68
--------------------
56
69
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.
60
73
61
74
.. image :: img/export_pck.webp
62
75
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.
66
80
67
81
.. note ::
68
82
@@ -86,19 +100,19 @@ process will build that type of file for the chosen platform.
86
100
use a tool-build of the engine (for security), so it's best to keep
87
101
the modding tool and game separate.
88
102
89
- Opening PCK files at runtime
90
- ----------------------------
103
+ Opening PCK or ZIP files at runtime
104
+ -----------------------------------
91
105
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.
95
109
96
110
.. tabs ::
97
111
.. code-tab :: gdscript GDScript
98
112
99
113
func _your_function():
100
114
# 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") )
102
116
103
117
if success:
104
118
# 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.
109
123
private void YourFunction()
110
124
{
111
125
// 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) );
113
127
114
128
if (success)
115
129
{
@@ -120,11 +134,14 @@ The PCK file contains a “mod_scene.tscn” test scene in its root.
120
134
121
135
.. warning ::
122
136
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).
128
145
129
146
To opt out of this behavior, pass ``false `` as the second argument to
130
147
: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.
134
151
Then, before loading the resource pack, you need to load its DLL as follows:
135
152
``Assembly.LoadFile("mod.dll") ``
136
153
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
+
137
169
Summary
138
170
-------
139
171
0 commit comments