@@ -6,7 +6,7 @@ Exporting packs, patches, and mods
66Use 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
1010deployed.
1111
1212Examples of this include...
@@ -18,11 +18,11 @@ Examples of this include...
1818These tools help developers to extend their development beyond the initial
1919release.
2020
21- Overview of PCK files
22- ---------------------
21+ Overview of PCK/ZIP files
22+ -------------------------
2323
2424Godot 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
3636The first part of using them involves exporting and delivering the project to
3737players. 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
5252original 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+
5467Generating 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,20 +134,39 @@ 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 >`.
131148
132149.. note ::
150+
133151 For a C# project, you need to build the DLL and place it in the project directory first.
134152 Then, before loading the resource pack, you need to load its DLL as follows:
135153 ``Assembly.LoadFile("mod.dll") ``
136154
155+ Troubleshooting
156+ ^^^^^^^^^^^^^^^
157+
158+ If you are loading a resource pack and are not noticing any changes, it may be
159+ due to the pack being loaded too late. This is particularly the case with menu
160+ scenes that may preload other scenes using
161+ :ref: `preload() <class_@GDScript_method_preload >`. This means that loading
162+ a pack in the menu will not affect the other scene that was already preloaded.
163+
164+ To avoid this, you need to load the pack as early as possible.
165+ To do so, create a new :ref: `autoload <doc_singletons_autoload >` script and
166+ call :ref: `ProjectSettings.load_resource_pack() <class_ProjectSettings_method_load_resource_pack >`
167+ in the autoload script's ``_init() `` function, rather than ``_enter_tree() ``
168+ or ``_ready() ``.
169+
137170Summary
138171-------
139172
0 commit comments