{"id":567,"date":"2018-04-26T19:42:39","date_gmt":"2018-04-27T02:42:39","guid":{"rendered":"https:\/\/invader.trystorymachine.com\/?p=567"},"modified":"2018-04-26T19:42:39","modified_gmt":"2018-04-27T02:42:39","slug":"dev-diary-branching-dialog","status":"publish","type":"post","link":"https:\/\/invader.trystorymachine.com\/?p=567","title":{"rendered":"Dev Diary: Branching Dialog"},"content":{"rendered":"<p>One of the new systems we&#8217;ve built for\u00a0DEAD SECRET CIRCLE is a branching dialog system. \u00a0As you explore the world you periodically interview suspects, and depending on your choices the conversation can go many different ways.<\/p>\n<p>Branching dialog systems are pretty common, and ours is not particularly exotic. But even in the implementation of a straightforward branching conversation system can be fairly complicated. For our system, I was interested in finding or building tools that would help me explore the flow of the dialog, and its various branches, in real-time as I was editing. \u00a0For me, the hardest part of this system is actually writing the dialog itself, so I needed a toolchain that would let me quickly edit and revise.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-573\" src=\"https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dsc_screenshot02-1024x576.png\" alt=\"dsc_screenshot02\" width=\"640\" height=\"360\" srcset=\"https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dsc_screenshot02-1024x576.png 1024w, https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dsc_screenshot02-300x169.png 300w, https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dsc_screenshot02-768x432.png 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/>Building a Dialog System<\/h2>\n<p>There are a number of tools available for creating branching dialog trees. \u00a0I looked at <a href=\"https:\/\/github.com\/InfiniteAmmoInc\/Yarn\">Yarn<\/a>, a Twine-like editor built for Night In the Woods. \u00a0<a href=\"http:\/\/www.chatmapper.com\">Chat Mapper<\/a> is a very serious&#8211;and very complicated-looking&#8211;tool that has an order of magnitude more features than I need. \u00a0I even realized that I wrote a markup syntax for branching dialog a decade ago that I&#8217;ve never used for anything. \u00a0Though there are a lot of tools out there,\u00a0it was hard to find something that matched my needs and powerful enough to justify not writing something myself.<br \/>\nIn the end I went with <a href=\"https:\/\/www.inklestudios.com\/inklewriter\/\">Inklewriter<\/a>, a web-based tool that allows you to quickly lay out (and play through) branching dialog trees. It was written as a Twine competitor, I think, but the feature set was just the right fit for DEAD SECRET CIRCLE. \u00a0It supports named variables, conditional branches, divert nodes (where dialog flow is diverted to another node in the middle of playback), and can output json. \u00a0The interface is simple but powerful, and I can share fully playable dialog sequences with others before we push it into the game. \u00a0Overall, it&#8217;s a smart tool made by developers who&#8217;ve done\u00a0a lot of interactive storytelling themselves.<\/p>\n<p>The next step was to write a Unity importer for Inklewriter&#8217;s output json. \u00a0Inkle Studios, the authors of Inklewriter, actually supply their own Unity plugin for <a href=\"https:\/\/www.inklestudios.com\/ink\/\">Ink<\/a>, their\u00a0(much more powerful, and complex) interactive novel language, but I needed to roll my own to use the simpler Inklewriter output. \u00a0I did this by creating a custom AssetPostprocessor\u00a0for text files that looks for json files and parses them. \u00a0The parser itself is straightforward&#8211;mostly just a translation of the json node hierarchy to a similar ScriptableObject graph which is written to disk as an asset file. \u00a0It also pulls all the strings out and puts them into a separate dictionary system, which provides key\/value pairs for all strings in the game and is our main infrastructure for localization. My workflow is to simply save Inklewriter&#8217;s output json into my Unity Assets folder and then point the runtime dialog system at the auto-generated asset, the root of which is the first node in the conversation. \u00a0At runtime, a dialog manager &#8220;runs&#8221; each node by displaying the node&#8217;s text, flipping node variables, and presenting the player with response choices, which select transitions to other nodes. \u00a0Text is pulled from the dictionary, and voice acting samples can also be pulled from another database using the same key. \u00a0I even made a nifty visualization tool out of Unity&#8217;s undocumented graph API.<\/p>\n<h2>Writing Branching Dialog<\/h2>\n<p>Once the tools and runtime were in order I was faced with the real task, which I had been avoiding: writing the actual dialog. \u00a0There are so many approaches to branching conversation design that it&#8217;s hard to know where to start. \u00a0I settled early on a fairly standard &#8220;call and response&#8221; model, in which\u00a0you ask the NPC a question from a list of options and they give you an answer, because it\u00a0mapped well to the story frame of interviewing suspects. \u00a0But where to go from there? \u00a0Should I encode a subtle moral choice into each question a la\u00a0<em>Mass Effect<\/em>? \u00a0Should I provide two plausible options and two joke options a la\u00a0<em>Disaster Report<\/em> (I call this the &#8220;DMV Written Test Design&#8221;)? \u00a0Should I allow the player chances to ask questions more than once, or should should choosing an option automatically close other options off (a la many games, but the best example is\u00a0<em>Firewatch<\/em>)? Should the player&#8217;s question choices inform the personality of their player character?\u00a0 The design of the conversation itself was much more daunting than the code to run it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-572 alignright\" src=\"https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dialog-tree.png\" alt=\"dialog tree\" width=\"435\" height=\"705\" srcset=\"https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dialog-tree.png 435w, https:\/\/invader.trystorymachine.com\/wp-content\/uploads\/2018\/04\/dialog-tree-185x300.png 185w\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" \/><\/p>\n<p>The main reason to h<br \/>\nave a branching dialog system to begin with is to deliver information to the player in a way that gives her some agency and (hopefully) engenders some\u00a0empathy for the NPC. \u00a0Some information is critical, and I can&#8217;t allow the player to miss it by making bad dialog choices. \u00a0Other information is optional, available to the players who choose to delve in further, who ask the game for more detail. \u00a0The DEAD<br \/>\nSECRET series is generally built upon a philosophy of narrative levels-of-detail: some folks will simply skim across the surface while others will choose to dive deep, and\u00a0both should have a good time. \u00a0I wanted the dialog system to be the same.<\/p>\n<p>In the end I settled on a model in which the player needs to make decisions, but there are no bad choices. \u00a0Once the player has chosen a question to ask, the conversation shifts in that direction, and (usually) does not return. \u00a0The player must choose which topics to broach, which bits they want to hone in on, but none of the choices are wrong or bad. \u00a0They just cause different tidbits of information to be revealed, and no matter what path is taken I can ensure that the critical pieces of information are displayed.<\/p>\n<p>Inklewriter&#8217;s toolset gave me enough power to author conversations with a lot of structural variance. \u00a0Some conversations loop (allowing several chances to ask the same question), others are nearly linear. \u00a0Some conversations result in significantly different revelations, others end up at the same place via different paths through the tree. \u00a0The structure is fairly free-form, which I like. \u00a0My goal is to make it feel as little like a mechanism to be reverse-engineered as possible.<\/p>\n<h2>Discoveries<\/h2>\n<p>I have never written branching dialog before, and I learned a lot in the process of writing for DEAD SECRET CIRCLE. \u00a0This stuff is probably old hat for folks that have built these types of systems before, but it was new to me.<\/p>\n<p>The biggest realization I had was that I could communicate the protagonist&#8217;s personality to the player through her questions. \u00a0Communicating the protagonist&#8217;s feelings is a constant struggle for me. \u00a0She has very few opportunities to talk about herself or what she is thinking. \u00a0Her main mode of communication is commentary on things that the player examines in the game world, but these messages must be succinct and to-the-point. There&#8217;s not a lot of time for introspection. \u00a0Figuring out that I could hint at her thought process by writing questions in a certain way was a revelation for me.<\/p>\n<p>I also learned how important it is to record dialog early, long before there are voice actors working on the project. \u00a0Jonny and his wife Shannon recorded all of the dialog in the game themselves, which let us test all kinds of critical systems like spatialized VO and lip synching. \u00a0But most importantly, it made it very obvious when a conversation made no sense. \u00a0Reading it out loud, with all the pauses and inflections and imperfect pronunciations that are normal to human speech, clearly separated the text that sounded natural from the text that did not. \u00a0By the time we did get voice acting done, we already knew what we wanted from nearly every line because we&#8217;d had placeholder audio in the game for months.<\/p>\n<p>Speaking of voice acting, I also learned how to make life really hard for the men and women who lent their voices to my characters. Forcing them to say foreign words in languages they don&#8217;t speak was one mistake. Relying on hard-to-say-out-loud technical words (like &#8220;ideomotor&#8221;) cost us some takes. \u00a0I briefly panicked when I realized I&#8217;d written a character with an accent that I couldn&#8217;t verify the accuracy of myself. \u00a0Fortunately we were lucky enough to work with seasoned pros who got through the minefield of my dialog text without losing limbs. \u00a0But next time I&#8217;ll try to remember that actual humans have to perform the words I write out loud.<\/p>\n<h2>And&#8230; Scene<\/h2>\n<p>The branching dialog system in DEAD SECRET CIRCLE was one of the most enjoyable parts of the project for me. \u00a0I liked building the system to run it and writing the dialog itself, and I learned a bunch in the process. \u00a0The original DEAD SECRET was a bit lonesome&#8211;there&#8217;s nobody in that house but you and the killer&#8211;and allowing direct interaction with a wider cast of characters was one of our core design goals for CIRCLE. \u00a0The dialog system (and related character animation and lip sync systems, which I&#8217;ll write about another time) ended up doing nearly all the heavy lifting here, and I&#8217;m really happy with the result.<\/p>\n<p>DEAD SECRET CIRCLE comes out pretty soon for both VR and traditional platforms. \u00a0There&#8217;s a <a href=\"http:\/\/store.steampowered.com\/app\/671920\/Dead_Secret_Circle\/\">Steam page up<\/a> if you are interested, and a <a href=\"http:\/\/deadsecret.com\">mailing list you can join<\/a> if you&#8217;d like to get updates about the game.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the new systems we&#8217;ve built for\u00a0DEAD SECRET CIRCLE is a branching dialog system. \u00a0As you explore the world you periodically interview suspects, and depending on your choices the conversation can go many different ways. Branching dialog systems are &hellip; <a href=\"https:\/\/invader.trystorymachine.com\/?p=567\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,18,5],"tags":[],"class_list":["post-567","post","type-post","status-publish","format-standard","hentry","category-dead-secret","category-dead-secret-dev-diary","category-game-design"],"_links":{"self":[{"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=567"}],"version-history":[{"count":8,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=\/wp\/v2\/posts\/567\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/invader.trystorymachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}