{"id":5905,"date":"2025-03-18T19:15:25","date_gmt":"2025-03-18T10:15:25","guid":{"rendered":"https:\/\/blog.criware.com\/?p=5905"},"modified":"2025-08-06T17:32:48","modified_gmt":"2025-08-06T08:32:48","slug":"using-sofdec-with-fungus","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2025\/03\/18\/using-sofdec-with-fungus\/","title":{"rendered":"Using Sofdec with Fungus"},"content":{"rendered":"<p>In stealth or action games, an officer often explains the mission before the actual gameplay. Static scenes like this, where interactivity is not required, can be implemented simply by displaying one or more video files.<\/p>\n<p><a href=\"https:\/\/fungusgames.com\/\">Fungus<\/a> is a free, open-source visual scripting tool for interactive storytelling and narrative-driven games in Unity. In this post, we will use Fungus to automatically play a different video during each narrative event. This is a great way to easily implement a mission briefing with Sofdec!<\/p>\n<div style=\"max-width: 700px; margin: 0 auto; margin-bottom: 30px;\">\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-5905-1\" width=\"800\" height=\"448\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/Using-Sofdec-with-Fungus_1.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/Using-Sofdec-with-Fungus_1.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/Using-Sofdec-with-Fungus_1.mp4<\/a><\/video><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>After installing the library within Unity, let&#8217;s create a simple narration within a game scene. By adding the Flowchart and SayDialog objects, we can implement a simple conversation scene.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5908\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/1.png\" alt=\"\" width=\"230\" height=\"281\" style=\"\n    display: block;\n    margin: 0 auto;\n\"\/><\/p>\n<p>For this demo, we will only create two conversation blocks in the FlowChart, Block1 and Block2, as shown in the diagram below, with the following conditions: \u2018Game Started\u2019 and \u2018Message Received\u2019, respectively.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5907\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/2.png\" alt=\"\" width=\"1485\" height=\"544\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/2.png 1485w, https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/2-300x110.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/2-1024x375.png 1024w, https:\/\/blog.criware.com\/wp-content\/uploads\/2025\/03\/2-768x281.png 768w\" sizes=\"auto, (max-width: 1485px) 100vw, 1485px\" \/><\/p>\n<p>Notice parts surrounded by a purple border. In <strong>\u2460<\/strong>, the method of the external script that plays the Sofdec video file is triggered, and in <strong>\u2461<\/strong>, the message sent from the external script at the end of the video playback is received, which causes Block2 to play. In other words, the conversation proceeds as following:<\/p>\n<ul style=\"font-size: 14px;\">\n<li>The conversation event Block 1 starts automatically at the start of the scene.<\/li>\n<li>When the conversation event reaches (A), the playback of the Sofdec video is triggered.<\/li>\n<li>When the Sofdec video finishes, the next conversation event is triggered (B).<\/li>\n<li>The final conversation event in Block2 proceeds.<\/li>\n<\/ul>\n<p>The timing of the conversation events and the videos are synchronized. For A, the process is straightforward as you simply need to trigger the Play() method provided by CriMana, Sofdec\u2019s runtime library. For B, you need a script that will send a message to Fungus once the video has finished playing. For example:<\/p>\n<pre style=\"width: 94%; margin-bottom: 0px; padding-bottom: 40px;\"><code class=\"hljs php\">\r\nvoid Update()\r\n{\r\n    \/\/ If the video has ended\r\n    if (currentStatus == CriWare.CriMana.Player.Status.PlayEnd)\r\n    {\r\n        \/\/ Call the Fungus block\r\n        Flowchart.BroadcastFungusMessage(messageName);\r\n        \/\/ Disable this script to prevent re-execution\r\n        this.enabled = false;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>In this example, for simplicity, we just monitor the status of the Sofdec player in the Update() function. Once it switches to PlayEnd, a message is sent to the Flowchart of Fungus.<\/p>\n<p>In addition to Fungus, many storytelling\/narration tools developed by third parties are available for Unity. Maybe you are already using one of them. If you can create a similar system, where CRIMana\u2019s playback functions can be called and the tool can receive a signal based on the video playback status, you will be able to synchronize the events and the Sofdec videos, just as we did above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In stealth or action games, an officer often explains the mission before the actual gameplay. Static scenes like this, where<\/p>\n","protected":false},"author":2,"featured_media":5918,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[6,7,23],"tags":[],"class_list":["post-5905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sofdec","category-tutorials","category-unity"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/5905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/comments?post=5905"}],"version-history":[{"count":8,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/5905\/revisions"}],"predecessor-version":[{"id":5919,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/5905\/revisions\/5919"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/5918"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=5905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=5905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=5905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}