Hi, I'm new to AC, and was trying to follow the instructions on how to integrate Yarn Spinner with AC (I'm making a game with a lot of dialogue and choices) but I'm not sure what I'm doing wrong or if it's my fault. I did step 1, installing Yarn and making a Dialogue Runner, then in step 2 I made the script and attached it to the Dialogue Runner, but couldn't assign it as the "Dialogue Runner component Inspector's Variable Storage field", it didn't recognise it as such. At the same time, in the console I started getting all sort of errors (I tried including an image here, but in case it doesn't show here's the link). I thought they might get fixed if I continue with the ActionList part, but I made a script there called ActionYarn.cs with the code, but more errors (the tutorial didn't mention making new folders though as stated in the Yarn Spinner integration instructions "Place this in a new folder and install this folder as a custom Actions directory in AC's Actions Manager", so I wasn't sure how to do that part, but anyways the errors were still there). I'm sorry if any of these questions are dumb, I'm not much of a programmer, I hope someone can help me integrate Yarn. Thank you in advance.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @pulpaulaa.
This may be due to a change on the Yarn Spinner side. It was previously a free plugin, but has since been made into a commercial product - is the latter the one you're using?
Hi! The paid version is optional, as a donation, the plugin is still free, here's the information (see the "Installing from other sources" part).
Thanks - I wasn't aware of that.
The API has indeed been updated for all sources. I've amended the wiki script to reflect these changes - give the scripts a try now.
Thank you! I made the script and attached it to the Dialogue Runner and it didn't give errors anymore, so it should work I think! Would it be okay if I asked you like in more detail on how to set up things from now for the workflow with yarn and ac? like for example what do you mean in the wiki, step 4, by creating the file in a folder and installing the folder instead of the file as a custom action (as seen in the tutorial for custom actions), and also, for step 5, when and where should i be using this action? An example would be incredibly helpful
This is fantastic, thank you! I used the updated script last night and it works fine for the most part, however yarnspinner tracks some internal vars to remember if you've spoken to a character before, will I need to manually create these vars in AC for that to work, or should internal vars be automatically handled?
Although I did trigger the dialogue directly via C# and not via the Yarn Action, so maybe that's why. Will check tonight.
Custom Actions are installed by informing the Actions Manager of their directory, rather than as individual files. That way, you can install multiple custom Actions in one go.
First place the ActionYarn script in a new folder, then open up the Actions Manager. Under the "Custom Actions scripts" section, click the folder icon to bring up the folder selection window, and then select the folder you made. The "Dialogue: Yarn" Action should then be listed under the "Dialogue" category.
The Action itself runs a Yarn node. Yarn works by having a Dialogue Runner component in the scene, which references a Yarn Project asset. The Action will run a given node found by the assigned Dialogue Runner - it should be run when you want the Yarn sequence to be played.
Hi again! Thank you for the explanation, I understand a lot better now and managed to make it work with an NPC, but I have a couple of follow up questions:
1. How do I change the characters animations while they talk? as this was previously handled automatically by AC with the talk animation, do I have to indicate this somehow in yarn?
2. Do I have to declare somehow a global variable in yarn so I don't get the warning that the variable hasn't been declared? I managed to make the dialogue check a global variable, but I get that warning, and also for some reason it always thinks the variable is 0, even when I change the starting value of the var, maybe it's because it hasn't been declared so it assumes it's 0? I'm not sure, here's a pic of the yarn dialogue file. The variable has the warnings and on hover it indicates "Implicitly declared in Hello.yarn, node Hello. Initial value: 0", so that's why I'm assuming the error is in not declaring it.
I've added a third script to the AC wiki, which you can install as an additional Dialogue View in the Dialogue Runner component. This will attempt to search for the referenced AC character and set their "IsTalking" bool to True.
What's the exact message you get?
Declaring variables is a case of using the <> statment - see Yarn's docs here:
https://docs.yarnspinner.dev/getting-started/writing-in-yarn/logic-and-variables
Thank you! I'll try that script.
The exact message I get is this one. I get how to declare variables in yarn, but this variable is global in the project, so I declared it in AC because many parts of the project have to check and edit that variable. Is there a way to "declare" this variable in the yarn script without setting it to a specific value? Like checking it from AC first and making that checked value the declared variable in yarn, I'm not sure if I'm explaining myself clearly.
I'm not sure if this is more of a Yarn issue than an AC one - the error message isn't coming from AC. Does declaring it always set the value when testing?
Hmm I don't really understand how things work more technically so I wouldn't know, sorry. But I'm trying to understand where it is I should declare the variable in the first place, I thought I had to make it in AC in the variables manager, but maybe it should be declared in yarn and then AC? I'm not sure. I tried doing that but it still doesn't work. Here's a link with photos of the yarn script declaring the variable, the variables manager and the object that should make the variable change. So, the variable is declared now in yarn, but it's still 0, because it's not connecting with the one I made in AC, that one does change when the bag object is clicked, but the yarn one doesn't, so I guess I could also make a node (in yarn) that changes the yarn variable and connect that in the actionlist editor, but it still would be 2 separate variables, when it should be the same one. I'm not sure how to connect them properly.
I've been following this post too as I'm also trying to hook YarnSpinner up to AC.
Your script works fine Chris, but there is one slight issue.
YarnSpinner tracks some internal variables, like how many times you've visited a dialogue node, and this is referenced like so:
<>
So I have a node called "RupertDriftwood" and when I hit it, I see a message in the console of:
"Cannot find AC Variable of the name Yarn.Internal.Visiting.RupertDriftwood"
If I create a global variable of type float with the name:
Yarn.Internal.Visiting.RupertDriftwood
Then that solves this problem, but it means we have to manually create global variables for every yarn node which is cumbersome.
It'd be great if AC auto-created a global (or local) variable that's prefixed with "Yarn.Internal." the first time it sees it.
bah looks like my double chevrons were removed from the post.
Imagine double-chevrons where there the outer double-quotes are:
"if visited("RupertDriftwood") is false"
Welcome to the community, @doglobster.
Variables can't be generated at runtime, but it may be possible to have AC keep track of visited nodes separately within the ACYarnVariables script - I'll have a look into it.
@pulpaulaa I'm not sure how much of this issue lies on the AC side - it may be worth getting in touch with the Yarn Spinner devs for advice. You shouldn't have to create two variables, however. Are you finding that if you run the "start" node, then your ActionList, and then "hello", the variable in Yarn is still unchanged?
@doglobster Here's an alternative version of the wiki's ACYarnVariables script that should save the visited nodes:
https://paste.ofcode.org/PZcDehGEcMJzjTnehmCmdZ
To use it, create a global String variable named "NodeVisited", and have the Dialogue Runner's On Node Start event run the script's OnNodeStart dynamic function.
Does that work on your end?
Ah great, thanks @ChrisIceBox. I'll give it a try when I'm back home later today.
I assume that there may be other internal variables tracked by YS, besides "Visiting", but looking at your script it could easily be adapted to cover those too. Let's start with this one and go from here. Thanks!
The other option I was thinking is that reading the YS nodes and generating global vars, could be a design-time step, managed via the unity editor. But lemme try this first. Thanks again.
@ChrisIceBox -- had to tweak it to increment the value onNodeComplete, rather than onNodeStart, otherwise the first time you meet a character they act like you've already met, but this worked great! And obviously, as it's ultimately driven by a global var, is preserved in the save file too.
Here are my tweaks:
https://paste.ofcode.org/3arLBLSvRBu83p4vRWe393Q
Awesome stuff, thank you!
No problem, thanks for the feedback.
I've merged the scripts into a dedicated package over on the Downloads page.