Page 1 of 1

Lua Function working in editor but not in build

Posted: Wed Aug 30, 2023 8:20 pm
by boz
Here's an example:

Code: Select all

Lua.RegisterFunction("IncrementEnervation", this, SymbolExtensions.GetMethodInfo(() => IncrementEnervation((double)0)));
This runs just fine from a DSFU node in editor, but when I'm in the actual build, it doesn't seem to do anything at all. Have you encountered anything like this before?

Re: Lua Function working in editor but not in build

Posted: Wed Aug 30, 2023 8:28 pm
by Tony Li
Hi,

What GameObject is that code's script on? If it's on the Dialogue Manager, make sure you call Lua.RegisterFunction() in Awake() or at least don't unregister it in OnDisable(). Otherwise, if a Dialogue Manager in the first scene registers it, and then you change to another scene with another Dialogue Manager, that other Dialogue Manager could unregister it as it's destroyed.

Another possibility: When making a build, Unity may make the build smaller by stripping out code that it thinks is unused.
It may be stripping out your IncrementEnervation method. To prevent this, turn off code stripping or edit a link.xml file to include the script/assembly. There's a link.xml file in the Dialogue System folder hierarchy. More info: Managed code stripping.

Re: Lua Function working in editor but not in build

Posted: Fri Sep 01, 2023 12:34 pm
by boz
Oh wow, I didn't know about that, thank you!

Re: Lua Function working in editor but not in build

Posted: Fri Sep 01, 2023 2:50 pm
by Tony Li
Glad to help!