{"id":26658,"date":"2018-06-19T15:03:00","date_gmt":"2018-06-19T15:03:00","guid":{"rendered":"http:\/\/www.gamasutra.com\/view\/news\/320206"},"modified":"2018-06-19T15:03:00","modified_gmt":"2018-06-19T15:03:00","slug":"blog-using-prefabs-in-game-development","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2018\/06\/19\/blog-using-prefabs-in-game-development\/","title":{"rendered":"Blog: Using prefabs in game development"},"content":{"rendered":"<p><strong><i><small> The following blog post, unless otherwise noted, was written by a member of Gamasutra\u2019s community.<br \/>The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company. <\/small><\/i><\/strong> <\/p>\n<hr \/>\n<div class=\"logos\">\n<div id=\"logo-1\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development.png\" \/><\/div>\n<div id=\"logo-2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-1.png\" \/><\/div>\n<\/div>\n<p><em>Prefabs are not a new topic to game developers. These\u00a0will be referenced in future articles of mine, so here&#8217;s an overview to a concept for\u00a0mastering massive content.<\/em><\/p>\n<p>If you\u2019ve ever had to deal with tons of objects across multiple scenes, you\u2019ll inevitably wish you could\u00a0group similar or exact copies together for quicker management.\u00a0If you\u2019ve added a desk lamp to 30 different office rooms in 15 different scenes, wouldn&#8217;t\u00a0it be nice to turn up the that\u00a0light&#8217;s intensity\u00a0once instead of <strong><em>450<\/em><\/strong> times?<\/p>\n<p><em><strong>That\u2019s the power of prefabs.\u00a0<\/strong><\/em><\/p>\n<p>So, what exactly is a prefab?\u00a0It&#8217;s a collection of game objects used in multiple places\u00a0across the game. It&#8217;s a concept I&#8217;ve made sure to use across past projects like <em>Six Days in Fallujah<\/em>, <em>Prey 2<\/em>, and <em>Mafia 3<\/em>.<\/p>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-2.png\" \/><\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-3.png\" \/><\/div>\n<\/div>\n<p>&#013;<br \/>\nA <strong>Prefab<\/strong>\u00a0should be\u00a0a <strong>Scene<\/strong>.\u00a0The only thing that should\u00a0make\u00a0a prefab different than a scene (a level, map, environment, etc.)\u00a0is it exists <u>inside<\/u> a scene.\u00a0A large city scene can have several small prefab neighborhoods and those in turn can have repeatable prefab houses inside of each.<\/p>\n<p>Some game engines develop prefabs as a unique feature, separate from a scene&#8217;s format. By developing a prefab as an extension of a classic scene means they inherit all features and power scene editing\u00a0has!<\/p>\n<p>Any feature that exists for a scene should exist for a prefab:<\/p>\n<ul>\n<li>A collection of models (a bench, a bus stop sign, a garbage can).<\/li>\n<p>&#013; <\/p>\n<li>A building with AI navigation and interaction nodes.<\/li>\n<p>&#013; <\/p>\n<li>An enemy with a unique change (BadGuy_Type_4 with dual pistols).<\/li>\n<p>&#013; <\/p>\n<li>A complex script sequence (depending on project&#8217;s\u00a0script file handling).<\/li>\n<p>&#013; <\/p>\n<li>A skybox with all associated FX and animation.<\/li>\n<p>&#013; <\/p>\n<li>A Security Door (a door model &amp; logic, security palm switch &amp; logic, emergency lighting &amp; logic, surrounded by cover nodes &amp; path volumes).<\/li>\n<p>&#013;\n<\/ul>\n<h2>Advantages<\/h2>\n<ol>\n<li>Repeat occurrences only have to be created once.\u00a0When the original prefab is modified, all instances are updated.<br \/>&#013; \u00a0<\/li>\n<p>&#013; <\/p>\n<li value=\"2\">Multiple people can work on the same scene by partitioning\u00a0the scene into prefabs.\u00a0Each user works on their individual prefab, testing their work in the\u00a0master scene.<\/li>\n<p>&#013;\n<\/ol>\n<h2>Game Usage<\/h2>\n<p>Prefabs should be\u00a0created in the editor as a new scene or from a selection within an existing scene. The most common type is a <strong><em>Static Prefab<\/em><\/strong>. They can be saved to the game library for reuse later.\u00a0When the game is built and run, all static prefabs are ungrouped (sometimes called exploded). All parts should have their name prefixed to the prefab&#8217;s unique name for reference. All game logic now points to unique items\u00a0maintaining unique scripting.<\/p>\n<p>In the editor they can also be exploded\u00a0into an existing scene to\u00a0creating unique, free roaming\u00a0objects, no longer connected to its source.\u00a0\u00a0<\/p>\n<p>Aside from static prefabs, <em><strong>Dynamic Prefabs<\/strong><\/em> are another option.\u00a0These are used to stream\u00a0in content. If done right, prefabs can\u00a0be the primary means all content is contained and streamed into the game.<\/p>\n<p>With procedural systems like <em><strong>Houdini<\/strong><\/em>, you could even extend prefabs into becoming\u00a0<em><strong>Smart Prefabs<\/strong><\/em>.\u00a0These feature a set of rules to decide what, where, and when to place a variety objects at different times.\u00a0This article is only about the core prefab concept though.<\/p>\n<p>Every scene can be made with a number of prefabs.\u00a0 Take a look at the following diagram as an example:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-4.png\" \/><\/p>\n<p>Now let&#8217;s see how prefabs let several people work on the scene:\u00a0<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-5.png\" \/><\/p>\n<p>The Art Team works on the <strong>Ground\u00a0Terrain A<\/strong> location:<\/p>\n<ul>\n<li><strong>Artist 1<\/strong> models <strong>Building D<\/strong> with indoor <strong>lighting<\/strong> to be used in 2 locations.<\/li>\n<p>&#013; <\/p>\n<li><strong>Artist 2<\/strong> models <strong>Building C<\/strong> to be used in 4 locations.<\/li>\n<p>&#013; <\/p>\n<li><strong>Artist 3<\/strong> models <strong>Building B<\/strong> to be used in 3 locations.<\/li>\n<p>&#013; <\/p>\n<li><strong>Artist 4<\/strong> models <strong>Building A<\/strong> with indoor <strong>lighting<\/strong> to be used in 4 locations.<\/li>\n<p>&#013;\n<\/ul>\n<p><strong>Artist 5<\/strong> is <strong>lighting<\/strong> the whole scene.\u00a0Some lighting features on-off logic with <strong>Gameplay<\/strong>.<\/p>\n<p>The <strong>Audio<\/strong> department is working on ambient <strong>Sound<\/strong> for the scene, mixed with <strong>Gameplay<\/strong>.<\/p>\n<p>The Design Team is providing gameplay to the <strong>Ground Terrain B<\/strong> location:<\/p>\n<ul>\n<li><strong>Designer 3<\/strong> is creating a generic prefab for assigning AI and stats for a <strong>Train Event<\/strong>.<\/li>\n<p>&#013; <\/p>\n<li><strong>Designer 2<\/strong> is creating <strong>City Tower<\/strong> logic to be used in 4 separate places in Ground B.<\/li>\n<p>&#013;\n<\/ul>\n<p>And lastly, <strong>Designer 1<\/strong> is providing gameplay for the overall scene in the <strong>Master\u00a0Scene<\/strong>.<\/p>\n<p>When any person is finished, they check their prefab into Source Control to share with the rest of the team.\u00a0When the master scene is opened again, any existing prefab is updated with the latest changes.\u00a0When new content ready, the user should be able to\u00a0pick them from the Resource Browser to add to the scene without restarting the editor.<\/p>\n<h2>Example Scene<\/h2>\n<p>Let&#8217;s group areas in a scene into prefabs, allowing several\u00a0people to work on each area:<\/p>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-6.png\" \/><\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-7.png\" \/><\/div>\n<\/div>\n<p>&#013;<br \/>\nA Designer takes a city block and creates a series of prefabs from it:<\/p>\n<ul>\n<li>Each building is named appropriately and saved as a prefab.<\/li>\n<p>&#013; <\/p>\n<li>A city block of prefabs is saved as one sector (optional).<\/li>\n<p>&#013; <\/p>\n<li>The master scene is now a framework of roads, game logic, prefabs, and sectors.<\/li>\n<p>&#013;\n<\/ul>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-8.png\" \/><\/p>\n<p>Original Scene<\/p>\n<\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-9.png\" \/><\/p>\n<p>Scene cut into 3 Game Sectors<\/p>\n<\/div>\n<\/div>\n<p>Artists individually open each prefab building to edit it:<\/p>\n<ul>\n<li>They can replace the stand-in model with a final version.<\/li>\n<p>&#013; <\/p>\n<li>They can even add new objects like\u00a0doors, windows, lamps, lights, etc.<\/li>\n<p>&#013; <\/p>\n<li>They can open the sector\u00a0to understand relations between each building prefab.<\/li>\n<p>&#013;\n<\/ul>\n<p>When a Designer re-opens the scene, all prefabs are updated with changes the Artists have made.<\/p>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-10.png\" \/><\/p>\n<p><strong>Artist 2<\/strong> works on an Apartment<br \/>&#013;<br \/>\nwithin Game Sector 1<\/p>\n<\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-11.png\" \/><\/p>\n<p><strong>Artist 3<\/strong> working on individual Motel Prefab<\/p>\n<\/div>\n<\/div>\n<p>How do you set up scenes to use sectors?\u00a0How do you work on them?\u00a0How should logic be arranged in them?\u00a0Before we talk about sectors, we need to understand how the scene played in the game (the <strong>Master, Main,\u00a0<\/strong>or<strong> Persistent<\/strong> scene) is organized.\u00a0Each scene consists of four basic components:<\/p>\n<p align=\"center\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-12.png\" \/><\/p>\n<p>Applying this concept to sectors, we can create a framework for maximum flexibility to add\u00a0(or remove) parts of the master scene without impacting the master\u00a0scene itself.\u00a0Each component can become a prefab for each sector.\u00a0<\/p>\n<p align=\"center\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-13.png\" \/><\/p>\n<p>Some prefabs don&#8217;t have to be exclusive to a sector; they can span several sectors.\u00a0This allows one person to check out a prefab to have access to the whole scene.\u00a0The disadvantage is when sectors are move around in the master\u00a0scene requiring contents to be moved manually to their new position.<\/p>\n<p align=\"center\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-14.png\" \/><\/p>\n<h2>Editing Prefabs<\/h2>\n<p>Two methods of prefab editing should exist:<\/p>\n<ol>\n<li>Edit the prefab in a new scene.<\/li>\n<p>&#013; <\/p>\n<li>Edit the prefab in the current scene.<\/li>\n<p>&#013;\n<\/ol>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-15.png\" \/><\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-16.png\" \/><\/div>\n<\/div>\n<p>Editing prefab \u201cA\u201d in a new scene isolated from original scene.<\/p>\n<div class=\"row2\">\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-17.png\" \/><\/div>\n<div class=\"column2\"><img decoding=\"async\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-18.png\" \/><\/div>\n<\/div>\n<p>Editing prefab \u201cA\u201d within the scene for instant feedback how it affects the scene.\u00a0<br \/>&#013;<br \/>\n(The fences will need to be modified.)<\/p>\n<p>By editing the prefab within the current scene, it removes switching back and forth between scenes to see your changes.<\/p>\n<p>By their nature, prefabs placed in scenes are instances of the original prefab.\u00a0If changes are made to the prefab, those changes propagate to all copies in every scene.\u00a0This can be helpful for example, if you want to change a texture or a light across a hundred copies.\u00a0You might however only want one small change.\u00a0 You need a way to remember those individual changes, instead of creating a new prefab for each change, exponentially increasing the number in\u00a0the game library.\u00a0<\/p>\n<p>This can be solved by tagging any differences and re-applying those differences after changes to the original is made.\u00a0Technically speaking, values unique to any type of object are stored in the parent prefab or scene file to override its original values.\u00a0When a change to the original is made, all copies reflect that change unless the value has been overridden on the instance.<\/p>\n<p>An \u201cAllow Deltas\u201d action provides a way to maintain these overrides.\u00a0With a prefab selected and \u201cAllow Deltas\u201d on (set to true), unique values will be accepted and maintained.\u00a0If \u201cAllow Deltas\u201d is turned off, all values are reset to their default.<\/p>\n<p align=\"center\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-19.png\" \/><br \/>&#013;<br \/>\nWithout Deltas, editing one prefab edits all of them.<\/p>\n<p align=\"center\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2018\/06\/blog-using-prefabs-in-game-development-20.png\" \/><br \/>&#013;<br \/>\nWith\u00a0Deltas, unique edits remain while<br \/>&#013;<br \/>\nany unchanged values inherit changes.<\/p>\n<p>To prevent the need to open prefabs, another option is enabling Child-picking. This ignores prefab containers and directly picks any object in view, no matter how deep they&#8217;re nested. Normal editing of prefabs should be outlined in red to indicate changing this one instance will change all instances of it.\u00a0 With Deltas on, objects inside prefabs should be outlined in cyan, letting you know any changes will only be applied to the selected object.<\/p>\n<p>Today\u2019s games involve thousands, if not millions, of objects. Managing all that content, making quick changes, and sharing team efforts, becomes a massive burden without a prefab system in place. If you want to spend more time discovering what\u2019s exciting about your game and less time playing 52,000 card pickup, then take the time to invest in a proper prefab feature.<\/p>\n<p><em>You can find more posts like this on my website at\u00a0<a href=\"https:\/\/www.curiousconstructs.com\">CuriousConstructs.com<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following blog post, unless otherwise noted, was written by a member of Gamasutra\u2019s community.The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company. Prefabs are not a new topic to game developers. These\u00a0will be referenced in future articles of mine, so here&#8217;s an overview to a concept [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":26659,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-26658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/26658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=26658"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/26658\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/26659"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=26658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=26658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=26658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}