Calling custom events

Calling custom events is a convienent way of integrating new code or third-party assets into Adventure Creator, as they can be called in addition to AC's regular code - rather than instead of. Adventure Creator's EventManager script provides a number of event handlers, which are listed in the scripting guide.

For the purpose of this tutorial, we'll add an event listener that gets called whenver a character speaks - this could be useful if we were looking to integrate a custom lip-syncing solution, for example. As this tutorial covers scripting, a basic knowledge of C# is assumed.

The EventManager script has a static event named OnStartSpeech, which is called whenever a character begins speaking. According to the scripting guide, any listener requires the following parameters:

  • AC.Char speakingCharacter - The character who is speaking. If null, the line is considered to be a narration
  • string speechText - The dialogue text
  • int lineID - The ID number of the speech line, as generated by the SpeechManager

Create a new C# script named SpeechListener and add the AC namespace at the top:

Let's create a function that acts as our listener. Name it GetSpeech, and add the parameters listed above:

Inside the function, add a simple Debug.Log to output the parameter values so that we can confirm it works:

We now just need to add this function as a listener to the OnStartSpeech function. If we do this within an OnEnable function, it will be added when the scene begins:

To prevent memory leaks, we should also remove this similarly in an OnDisable function:

And that's it! If you add this script to your Adventure Creator scene, you should find that the speech text is output to the Console as it is triggered:

"Adventure Creator" and this website are copyright Chris Burton, ICEBOX Studios

Go to top