Page 1 of 1

How to modifiy variable from editor script (not runtime)

Posted: Mon Apr 11, 2022 9:15 pm
by Strook
Hello!

How can I modify a variable from an editor script at editor time?

Example: I have a variable "Foo" of type number, and a Editor script that needs to set this variable to a certain number at editor time.



Thanks!

Re: How to modifiy variable from editor script (not runtime)

Posted: Mon Apr 11, 2022 9:37 pm
by Tony Li
Hi,

At runtime, the dialogue database variables are copied to Lua variables, so you'd use DialogueLua.SetVariable().

At editor time, on the other hand, they're still just dialogue database variables. There is no Lua environment at editor time. You need a reference to your dialogue database. If you don't have one, EditorTools.FindInitialDatabase() will return the database that's assigned to the open scene's Dialogue Manager:

Code: Select all

DialogueDatabase db = PixelCrushers.DialogueSystem.EditorTools.FindInitialDatabase();
Then you can call DialogueDatabase.GetVariable() to get the variable and set its value:

Code: Select all

PixelCrushers.DialogueSystem.Variable variable = db.GetVariable("Foo");
variable.InitialFloatValue = 42;

Re: How to modifiy variable from editor script (not runtime)

Posted: Mon Apr 11, 2022 9:39 pm
by Strook
perfect, thanks! That's exactly what I was looking for 👍

Re: How to modifiy variable from editor script (not runtime)

Posted: Mon Apr 11, 2022 9:44 pm
by Tony Li
Glad to help!