exporting_pcks.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. .. _doc_exporting_pcks:
  2. Exporting packs, patches, and mods
  3. ==================================
  4. Use cases
  5. ---------
  6. Oftentimes one would like to add functionality to one's game after it has been
  7. deployed.
  8. Examples of this include...
  9. - Downloadable Content: the ability to add features and content to one's game.
  10. - Patches: the ability to fix a bug that is present in a shipped product.
  11. - Mods: grant other people the ability to create content for one's game.
  12. These tools help developers to extend their development beyond the initial
  13. release.
  14. Overview of PCK files
  15. ---------------------
  16. Godot enables this via a feature called **resource packs** (PCK files,
  17. with extension ``.pck``).
  18. **Advantages:**
  19. - incremental updates/patches
  20. - offer DLCs
  21. - offer mod support
  22. - no source code disclosure needed for mods
  23. - more modular project structure
  24. - users don't have to replace the entire game
  25. The first part of using them involves exporting and delivering the project to
  26. players. Then, when one wants to add functionality or content later on, they
  27. just deliver the updates via PCK files to the users.
  28. PCK files usually contain, but are not limited to:
  29. - scripts
  30. - scenes
  31. - shaders
  32. - models
  33. - textures
  34. - sound effects
  35. - music
  36. - any other asset suitable for import into the game
  37. The PCK files can even be an entirely different Godot project, which the
  38. original game loads in at runtime.
  39. Generating PCK files
  40. --------------------
  41. In order to pack all resources of a project into a PCK file open the project
  42. and go to Project/Export and click on “Export PCK/Zip”. Also make sure to have
  43. an export template selected while doing so.
  44. .. image:: img/export_pck.png
  45. Another method would be to :ref:`export from the command line <doc_command_line_tutorial_exporting>`.
  46. If the output file ends with a PCK or ZIP file extension, then the export
  47. process will build that type of file for the chosen platform.
  48. .. note::
  49. If one wishes to support mods for their game, they will need their users to
  50. create similarly exported files. Assuming the original game expects a
  51. certain structure for the PCK's resources and/or a certain interface for
  52. its scripts, then either...
  53. 1. The developer must publicize documentation of these expected structures/
  54. interfaces, expect modders to install Godot Engine, and then also expect
  55. those modders to conform to the documentation's defined API when building
  56. mod content for the game (so that it will work). Users would then use
  57. Godot's built in exporting tools to create a PCK file, as detailed
  58. above.
  59. 2. The developer uses Godot to build a GUI tool for adding their exact API
  60. content to a project. This Godot tool must either run on a tools-enabled
  61. build of the engine or have access to one (distributed alongside or
  62. perhaps in the original game's files). The tool can then use the Godot
  63. executable to export a PCK file from the command line with
  64. :ref:`OS.execute() <class_OS_method_execute>`. It makes the most sense for the
  65. game to not use a tool-build though (for security) and for the modding
  66. tools to *do* use a tool-enabled engine build.
  67. Opening PCK files at runtime
  68. ----------------------------
  69. To import a PCK file, one uses a one-liner. Keep in mind, there is no
  70. error or exception if the import fails. Instead, one might have to create some
  71. validation code as a layer on top. The following example expects a “mod.pck”
  72. file in the directory of the games executable. The PCK file contains a
  73. “mod_scene.tscn” test scene in its root.
  74. .. tabs::
  75. .. code-tab:: gdscript GDScript
  76. func _your_function():
  77. ProjectSettings.load_resource_pack("res://mod.pck")
  78. # Now one can use the assets as if they had them in the project from the start
  79. var imported_scene = load("res://mod_scene.tscn")
  80. .. code-tab:: csharp
  81. private void YourFunction()
  82. {
  83. ProjectSettings.LoadResourcePack("res://mod.pck");
  84. // Now one can use the assets as if they had them in the project from the start
  85. var importedScene = (PackedScene)ResourceLoader.Load("res://mod_scene.tscn");
  86. }
  87. .. warning::
  88. By default, if you import a file with the same file path/name as one you already have in your
  89. project, the imported one will replace it. This is something to watch out for when
  90. creating DLC or mods (solved easily with a tool isolating mods to a specific mods
  91. subfolder). However, it is also a way of creating patches for one's own game. A
  92. PCK file of this kind can fix the content of a previously loaded PCK.
  93. To opt out of this behavior, pass ``false`` as the second argument to
  94. :ref:`ProjectSettings.load_resource_pack() <class_ProjectSettings_method_load_resource_pack>`.
  95. .. note::
  96. For a C# project, you need to build the DLL and place it in the project directory first.
  97. Then, before loading the resource pack, you need to load its DLL as follows:
  98. ``Assembly.LoadFile("mod.dll")``
  99. Summary
  100. -------
  101. This tutorial should illustrate how easy adding mods, patches or DLC to a game
  102. is. The most important thing is to identify how one plans to distribute future
  103. content for their game and develop a workflow that is customized for that
  104. purpose. Godot should make that process smooth regardless of which route a
  105. developer pursues.