I’ve recently started using the Ink Integration for Unity to add narrative and dialogue to my game. I was looking for ways to play animations during specific lines of dialogue. I’m currently doing this using tags in the Ink script.
This approach was suggested in the Ink documentation for playing other media like .ogg audio files. I also found this blog post helpful for how to access the Ink tags (in this case for the character’s name) for the current line of the story.
I’ve provided my approach below and a link to the full Unity C# script, I hope you find it helpful!
Ink- Adding tags to the Ink script
I used a naming convention for my animation tags, so that my C# script could recognise when a tag was for a character name or an animation.
Animation tag: start with a “anim” prefix, then a reference to the character, and end with the name of the animation clip. Note: The last part of the tag needs to match the animation clip name.
E.g. #anim_c1_anim1
Character name tag: I didn’t add a prefix for character names.
This script can parse through multiple tags on a line. For example if I want to play an animation as well as display a character name.
C#- Parsing though Ink dialogue tags
While “currentStory.canContinue” is true, the script will Continue through the currentStory and parse the tags for the current line of dialogue using the “PopulateNameAnimTags( )” method. This is called once per frame in the Update( ) method.
I created Lists<> for each character’s animation tags, as well as a List<> for all name tags. When a tag is added to the animation list, it is played in the same frame by the AnimationPlayer( ) method.
For my script, I identified a name tag by any tag that doesn’t have an “anim” prefix. For my purposes I only needed two types of tags.
Lists are cleared when the story continues to the next line, so the script only uses tags for the current line.
C#- Playing Unity animation clips from Ink tags
After the “PopulateNameAnimTags( )” Adds an animation tag to a List, the “AnimationPlayer()” trims the tag to remove the prefix. It then passes the Animation Clip name to that character’s Animator.
My method is setup for two characters but this could be expanded, or refactored so the same IF statement can handle multiple characters.
C# – Full script
You can download the full script from GitHub.