SofdecTutorials

Using Sofdec with Fungus

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.

Fungus 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!

 

After installing the library within Unity, let’s create a simple narration within a game scene. By adding the Flowchart and SayDialog objects, we can implement a simple conversation scene.

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: ‘Game Started’ and ‘Message Received’, respectively.

Notice parts surrounded by a purple border. In , the method of the external script that plays the Sofdec video file is triggered, and in , 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:

  • The conversation event Block 1 starts automatically at the start of the scene.
  • When the conversation event reaches (A), the playback of the Sofdec video is triggered.
  • When the Sofdec video finishes, the next conversation event is triggered (B).
  • The final conversation event in Block2 proceeds.

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’s runtime library. For B, you need a script that will send a message to Fungus once the video has finished playing. For example:


void Update()
{
    // If the video has ended
    if (currentStatus == CriWare.CriMana.Player.Status.PlayEnd)
    {
        // Call the Fungus block
        Flowchart.BroadcastFungusMessage(messageName);
        // Disable this script to prevent re-execution
        this.enabled = false;
    }
}

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.

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’s 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.