YarnCommand
attribute, or manually, using the DialogueRunner
's AddCommandHandler
method.YarnCommand
attributeYarnCommand
attribute lets you expose methods in a MonoBehaviour
to Yarn Spinner.YarnCommand
attribute to a method, you specify what name the command should have in Yarn scripts. You can then use that name as a command.FadeCamera.cs
, you can run this code in your Yarn scripts like this:static
, you call it with the name of the game object you want the command to run on.CharacterMovement.cs
, create a new game object called MyCharacter
, and attach the CharacterMovement
script to that game object, you can run this code in your Yarn scripts like this:YarnCommand
may take the following kinds of parameters:string
int
float
bool
true
and false
. Additionally, the name of the parameter is interpreted as true
.GameObject
null
will be passed.Component
(or its subclasses)null
will be passed.AddCommandHandler
method.AddCommandHandler
takes two parameters: the name of the command as it should be used in Yarn Spinner, and a method to call when the function is run.AddCommandHandler
that takes parameters, you must list the types of those parameters.camera_look
in the Dialogue Runner you attach.AddCommandHandler
method and the YarnCommand
attribute. Both of these provide effectively the same functionality, and under-the-hood the YarnCommand
attribute is even a wrapper around the AddCommandHandler
call. So if there are two different ways to achieve the same thing when should you use each one?YarnCommand
attribute allows you to tag specific methods as being a command, Yarn Spinner will then automatically handle the binding and connection of the the command in text to the method call in C#. AddCommandHandler
method allows you to manually connect a method in C# to a command in Yarn, letting you set the name of the command and which method it connect to, giving you the control over the binding.YarnCommand
attribute is the better option, it is easier to use and maps well to how we find most people use commands, that is to say calling specific methods on specific GameObjects. This convenience however does come at a cost of flexibility as your YarnCommands
either need to be on static methods or follow specific calling conventions which may not be what you need or want. The YarnCommand
works best in our opinion when your commands are calling into specific GameObjects in your scene, so it works very well for moving, animating, or changing characters and items in a scene. For larger gameplay changing moments such as loading new scenes, or moving between dialogue and the rest of your game, or for more global events like declaring a save should happen or an achievement has been unlocked the AddCommandHandler
method is better.YarnCommand
attribute performs a search on your project to locate and bind commands to specific method calls which the AddCommandHandler
does not have to do. While for the most part this lookup will go by unnoticed, on larger projects you may find this adds a noticeable performance penalty.YarnCommand
attribute, or the AddCommandHandler
method, and the method you're using it with is a coroutine (that is, it returns IEnumerator
, and yields
objects like WaitForSeconds
), Yarn Spinner will pause execution of your dialogue when the command is called.<<wait>>
. (You don't have to do this in your own games, because <<wait>>
is already added for you, but this example shows you how you'd do it yourself.)YarnFunction
attribute, or the AddFunction
method on a Dialogue Runner. These work very similarly to commands, but with two important distinctions:static
.string
int
float
bool
YarnCommand
and YarnFunction
attributes when your game first starts up, as well as when a Dialogue Runner is told to run a Yarn Project.