YarnSpinner-Unity icon indicating copy to clipboard operation
YarnSpinner-Unity copied to clipboard

I want DialogueRunner.AddScript(string text) back!

Open Gumoumou opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. For older version of Yarnspinner I could use AddScript(string text) to add dialogue in game,that is very flexible and easy to use. But now I have to use Add(YarnProgram scriptToLoad) , it require a YarnProgram(Is there a way to create YarnProgram at runtime?) I want add dialogue at runtime ! Describe the solution you'd like I want DialogueRunner.AddScript(string text) back! Or a method that allow me to create YarnProgram at runtime!

Gumoumou avatar Oct 12 '20 09:10 Gumoumou

You don't need to "create" a YarnProgram at runtime, you can just reference a pre-existing one. For example, I have a "level properties" object that holds a public YarnProgram variable/reference. When the object is loaded, it calls DialogueRunner.Add(reference).

Moxie-Cat avatar Nov 05 '20 20:11 Moxie-Cat

I won't speak for Secret Lab folks but I imagine we won't be implementing this in Yarn Spinner Unity since it goes against a lot of the tool design, which is about pre-compiling the bytecode to do static analysis and other nice things etc.

But if you (or anyone who googles this later) want to hack this in yourself, the code in /Editor/YarnImporter.cs looks pretty straightforward to copy+paste and modify for your own C# script. YarnImporter.ImportYarn() basically just reads all the text from a .yarn file and feeds it into Yarn.Compiler.Compiler.Compile()... make sure you include using Yarn.Compiler;

https://github.com/YarnSpinnerTool/YarnSpinner-Unity/blob/develop/Editor/YarnImporter.cs#L221-L245

radiatoryang avatar Jan 15 '21 23:01 radiatoryang

Support for runtime compilation is actually a use case I'm seeing quite often, and it's highly likely that we'll include support for it in a future release. Not 2.0, but probably not too far after that. I'll leave this issue open for now, but it may get closed as a duplicate if we end up creating a main "we should allow runtime compilation" ticket.

desplesda avatar Jul 09 '21 06:07 desplesda