creating_units.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" >
  3. <head>
  4. <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
  5. <meta property="article:modified_time" content="2026-02-18T11:16:10+00:00" /><meta property="og:title" content="Creating Units" />
  6. <meta property="og:type" content="website" />
  7. <meta property="og:url" content="https://docs.crownengine.org/html/latest/units/creating_units.html" />
  8. <meta property="og:site_name" content="Crown 0.60.0 Manual" />
  9. <meta property="og:description" content="Overview: There are two distinct concepts you need to keep in mind: Unit prefab: a.unit resource stored in your project that describes a Unit hierarchy and all its components and properties., Unit instance: a concrete instance of that prefab that exists in a running World.. Yo..." />
  10. <meta name="description" content="Overview: There are two distinct concepts you need to keep in mind: Unit prefab: a.unit resource stored in your project that describes a Unit hierarchy and all its components and properties., Unit instance: a concrete instance of that prefab that exists in a running World.. Yo..." />
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  12. <title>Creating Units &mdash; Crown 0.60.0 Manual 0.62.0 documentation</title>
  13. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  14. <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  15. <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
  16. <link rel="shortcut icon" href="../_static/org.crownengine.Crown.svg"/>
  17. <link rel="canonical" href="https://docs.crownengine.org/html/latest/units/creating_units.html" />
  18. <!--[if lt IE 9]>
  19. <script src="../_static/js/html5shiv.min.js"></script>
  20. <![endif]-->
  21. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  22. <script src="../_static/jquery.js"></script>
  23. <script src="../_static/underscore.js"></script>
  24. <script src="../_static/doctools.js"></script>
  25. <script src="../_static/js/theme.js"></script>
  26. <link rel="index" title="Index" href="../genindex.html" />
  27. <link rel="search" title="Search" href="../search.html" />
  28. <link rel="copyright" title="Copyright" href="../copyright.html" />
  29. <link rel="next" title="Rendering" href="../rendering/index.html" />
  30. <link rel="prev" title="Introduction" href="introduction.html" />
  31. </head>
  32. <body class="wy-body-for-nav">
  33. <div class="wy-grid-for-nav">
  34. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  35. <div class="wy-side-scroll">
  36. <div class="wy-side-nav-search" >
  37. <a href="../index.html">
  38. <img src="../_static/org.crownengine.Crown.svg" class="logo" alt="Logo"/>
  39. </a>
  40. <div class="version">
  41. Crown 0.60.0 Manual
  42. </div>
  43. <div role="search">
  44. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  45. <input type="text" name="q" placeholder="Search docs" />
  46. <input type="hidden" name="check_keywords" value="yes" />
  47. <input type="hidden" name="area" value="default" />
  48. </form>
  49. </div>
  50. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  51. <ul class="current">
  52. <li class="toctree-l1"><a class="reference internal" href="../changelog.html">Changelog</a></li>
  53. <li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction</a></li>
  54. <li class="toctree-l1"><a class="reference internal" href="../installing_crown/index.html">Installing Crown</a></li>
  55. <li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li>
  56. <li class="toctree-l1"><a class="reference internal" href="../level_editor/index.html">Level Editor</a></li>
  57. <li class="toctree-l1"><a class="reference internal" href="../importing_resources/index.html">Importing Resources</a></li>
  58. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Units</a><ul class="current">
  59. <li class="toctree-l2"><a class="reference internal" href="introduction.html">Introduction</a></li>
  60. <li class="toctree-l2 current"><a class="current reference internal" href="#">Creating Units</a><ul>
  61. <li class="toctree-l3"><a class="reference internal" href="#overview">Overview</a></li>
  62. <li class="toctree-l3"><a class="reference internal" href="#from-the-level-editor">From the Level Editor</a></li>
  63. <li class="toctree-l3"><a class="reference internal" href="#from-the-project-browser">From the Project Browser</a></li>
  64. <li class="toctree-l3"><a class="reference internal" href="#from-imported-resources">From imported resources</a></li>
  65. <li class="toctree-l3"><a class="reference internal" href="#spawning-units">Spawning Units</a></li>
  66. </ul>
  67. </li>
  68. </ul>
  69. </li>
  70. <li class="toctree-l1"><a class="reference internal" href="../rendering/index.html">Rendering</a></li>
  71. <li class="toctree-l1"><a class="reference internal" href="../physics/index.html">Physics</a></li>
  72. <li class="toctree-l1"><a class="reference internal" href="../gameplay/index.html">Writing Gameplay</a></li>
  73. <li class="toctree-l1"><a class="reference internal" href="../deploying/index.html">Deploying</a></li>
  74. <li class="toctree-l1"><a class="reference internal" href="../reference/index.html">Reference</a></li>
  75. <li class="toctree-l1"><a class="reference internal" href="../lua_api.html">Lua API reference</a></li>
  76. <li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
  77. <li class="toctree-l1"><a class="reference internal" href="../copyright.html">License</a></li>
  78. <li class="toctree-l1"><a class="reference internal" href="../hackers/index.html">Engine Hackers</a></li>
  79. </ul>
  80. </div>
  81. </div>
  82. </nav>
  83. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  84. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  85. <a href="../index.html">Crown 0.60.0 Manual</a>
  86. </nav>
  87. <div class="wy-nav-content">
  88. <div class="rst-content">
  89. <div role="navigation" aria-label="Page navigation">
  90. <ul class="wy-breadcrumbs">
  91. <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
  92. <li><a href="index.html">Units</a> &raquo;</li>
  93. <li>Creating Units</li>
  94. <li class="wy-breadcrumbs-aside">
  95. <a href="../_sources/units/creating_units.rst.txt" rel="nofollow"> View page source</a>
  96. </li>
  97. </ul>
  98. <hr/>
  99. </div>
  100. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  101. <div itemprop="articleBody">
  102. <section id="creating-units">
  103. <h1>Creating Units<a class="headerlink" href="#creating-units" title="Permalink to this headline">¶</a></h1>
  104. <section id="overview">
  105. <h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
  106. <p>There are two distinct concepts you need to keep in mind:</p>
  107. <ul class="simple">
  108. <li><p>Unit <strong>prefab</strong>: a <code class="docutils literal notranslate"><span class="pre">.unit</span></code> resource stored in your project that describes
  109. a Unit hierarchy and all its components and properties.</p></li>
  110. <li><p>Unit <strong>instance</strong>: a concrete instance of that prefab that exists in a
  111. running World.</p></li>
  112. </ul>
  113. <p>You author and edit prefabs in the tools (Level Editor, Unit Editor and
  114. importers). At runtime you instantiate prefabs from Lua and manipulate the
  115. resulting Unit instances.</p>
  116. <p>You do <em>not</em> write <code class="docutils literal notranslate"><span class="pre">.unit</span></code> files from Lua, and you do <em>not</em> author prefabs
  117. directly from gameplay code.</p>
  118. </section>
  119. <section id="from-the-level-editor">
  120. <h2>From the Level Editor<a class="headerlink" href="#from-the-level-editor" title="Permalink to this headline">¶</a></h2>
  121. <p>Prefabs can be created in a number of ways. Arguably the simplest way to
  122. create new Units is to use the <a class="reference internal" href="../level_editor/level_editor.html#level-editor"><span class="std std-ref">Level Editor</span></a> and then
  123. save what you have built as a prefab.</p>
  124. <ol class="arabic simple">
  125. <li><dl class="simple">
  126. <dt><strong>Open or create a Level</strong></dt><dd><ul class="simple">
  127. <li><p>Open an existing Level from the <a class="reference internal" href="../level_editor/project_browser.html"><span class="doc">Project Browser</span></a>, or</p></li>
  128. <li><p>create a new one with <code class="docutils literal notranslate"><span class="pre">File</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">New</span> <span class="pre">Level</span></code>.</p></li>
  129. </ul>
  130. </dd>
  131. </dl>
  132. </li>
  133. <li><dl class="simple">
  134. <dt><strong>Place a Unit in the Level</strong></dt><dd><ul class="simple">
  135. <li><p>Place a new unit with <code class="docutils literal notranslate"><span class="pre">Spawn</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Primitives</span></code>, or drag an existing
  136. Unit prefab from the Project Browser into
  137. the <a class="reference internal" href="../level_editor/level_viewport.html"><span class="doc">Level Viewport</span></a></p></li>
  138. <li><p>Use the <a class="reference internal" href="../level_editor/inspector.html"><span class="doc">Inspector</span></a> to add or remove components and
  139. to fine‑tune their properties</p></li>
  140. </ul>
  141. </dd>
  142. </dl>
  143. </li>
  144. <li><dl class="simple">
  145. <dt><strong>Save the Unit as prefab</strong></dt><dd><ul class="simple">
  146. <li><p>In the <a class="reference internal" href="../level_editor/level_tree.html"><span class="doc">Level Tree</span></a>, right‑click the Unit you want
  147. to turn into a prefab</p></li>
  148. <li><p>Choose <code class="docutils literal notranslate"><span class="pre">Save</span> <span class="pre">as</span> <span class="pre">Prefab...</span></code></p></li>
  149. <li><p>In the file dialog, pick a target folder and a unique name, then click
  150. <code class="docutils literal notranslate"><span class="pre">Save</span></code></p></li>
  151. </ul>
  152. </dd>
  153. </dl>
  154. </li>
  155. </ol>
  156. <p>The editor will:</p>
  157. <ul class="simple">
  158. <li><p>create a new <code class="docutils literal notranslate"><span class="pre">.unit</span></code> resource at the chosen location</p></li>
  159. <li><p>automatically replace the Unit in the Level with an instance of the newly
  160. created prefab</p></li>
  161. </ul>
  162. <p>From now on:</p>
  163. <ul class="simple">
  164. <li><p>editing the prefab will update all instances that use it unless they
  165. explicitly override properties or children</p></li>
  166. <li><p>editing the instance in the Level will create per‑instance overrides</p></li>
  167. </ul>
  168. </section>
  169. <section id="from-the-project-browser">
  170. <h2>From the Project Browser<a class="headerlink" href="#from-the-project-browser" title="Permalink to this headline">¶</a></h2>
  171. <p>Sometimes you want to start from a blank prefab instead of capturing an
  172. existing Unit from a Level. You can do this directly from the
  173. <a class="reference internal" href="../level_editor/project_browser.html"><span class="doc">Project Browser</span></a>:</p>
  174. <ol class="arabic simple">
  175. <li><p>Right‑click the folder where you want to create the prefab</p></li>
  176. <li><p>Choose <code class="docutils literal notranslate"><span class="pre">New</span> <span class="pre">Unit...</span></code></p></li>
  177. <li><p>Enter a name for the prefab and confirm</p></li>
  178. </ol>
  179. <p>This creates an empty <code class="docutils literal notranslate"><span class="pre">.unit</span></code> resource that you can then edit:</p>
  180. <ul class="simple">
  181. <li><p>by opening it in the Unit Editor, or</p></li>
  182. <li><p>by selecting any instance that uses the prefab in a Level and clicking
  183. <code class="docutils literal notranslate"><span class="pre">Open</span> <span class="pre">Prefab</span></code> in the <a class="reference internal" href="../level_editor/inspector.html"><span class="doc">Inspector</span></a>.</p></li>
  184. </ul>
  185. </section>
  186. <section id="from-imported-resources">
  187. <h2>From imported resources<a class="headerlink" href="#from-imported-resources" title="Permalink to this headline">¶</a></h2>
  188. <p>Some importers generate Units automatically as part of their workflow:</p>
  189. <ul class="simple">
  190. <li><p><a class="reference internal" href="../importing_resources/importing_scenes.html"><span class="doc">Importing Scenes</span></a> generates Units for each
  191. geometry, light and camera in a FBX file.</p></li>
  192. <li><p><a class="reference internal" href="../importing_resources/importing_sprites.html"><span class="doc">Importing Sprites</span></a> generates a Unit prefab,
  193. materials and other resources from a spritesheet.</p></li>
  194. </ul>
  195. <p>These generated Units appear in the Project Browser like any other <code class="docutils literal notranslate"><span class="pre">.unit</span></code>
  196. resource and can be:</p>
  197. <ul class="simple">
  198. <li><p>placed in Levels</p></li>
  199. <li><p>opened and modified in the Unit Editor</p></li>
  200. <li><p>used as base prefabs for derived units</p></li>
  201. </ul>
  202. </section>
  203. <section id="spawning-units">
  204. <h2>Spawning Units<a class="headerlink" href="#spawning-units" title="Permalink to this headline">¶</a></h2>
  205. <p>Lua gameplay code never creates new <code class="docutils literal notranslate"><span class="pre">.unit</span></code> resources. Instead, it creates
  206. instances of existing prefabs inside a World. The act of creating unit
  207. instances at runtime is called <strong>spawning</strong>.</p>
  208. <div class="highlight-lua notranslate"><div class="highlight"><pre><span></span><span class="n">player</span> <span class="o">=</span> <span class="n">World</span><span class="p">.</span><span class="n">spawn_unit</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="s2">&quot;units/player/player&quot;</span><span class="p">)</span>
  209. </pre></div>
  210. </div>
  211. <p>This:</p>
  212. <ul class="simple">
  213. <li><p>instantiates the unit <code class="docutils literal notranslate"><span class="pre">units/player/player</span></code> into the specified <code class="docutils literal notranslate"><span class="pre">world</span></code></p></li>
  214. <li><p>returns a Unit handle you can store and use from Lua</p></li>
  215. </ul>
  216. <p>See <a class="reference internal" href="../gameplay/unit_interaction.html"><span class="doc">Interacting with Units</span></a> for a detailed walkthrough of unit
  217. handles, Script Component and callbacks.</p>
  218. </section>
  219. </section>
  220. </div>
  221. </div>
  222. <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
  223. <a href="introduction.html" class="btn btn-neutral float-left" title="Introduction" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
  224. <a href="../rendering/index.html" class="btn btn-neutral float-right" title="Rendering" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  225. </div>
  226. <hr/>
  227. <div role="contentinfo">
  228. <p>&#169; <a href="../copyright.html">Copyright</a> Except where otherwise noted, content on this page is licensed under a CC-BY-SA 4.0 Int. License.
  229. <span class="lastupdated">Last updated on Feb 18, 2026.
  230. </span></p>
  231. </div>
  232. Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
  233. <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
  234. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  235. </footer>
  236. </div>
  237. </div>
  238. </section>
  239. </div>
  240. <script>
  241. jQuery(function () {
  242. SphinxRtdTheme.Navigation.enable(true);
  243. });
  244. </script>
  245. <!-- Theme Analytics -->
  246. <script async src="https://www.googletagmanager.com/gtag/js?id=G-XNVGCMNDZH"></script>
  247. <script>
  248. window.dataLayer = window.dataLayer || [];
  249. function gtag(){dataLayer.push(arguments);}
  250. gtag('js', new Date());
  251. gtag('config', 'G-XNVGCMNDZH', {
  252. 'anonymize_ip': true,
  253. });
  254. </script>
  255. </body>
  256. </html>