Lua Function working in editor but not in build

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Lua Function working in editor but not in build

Post 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?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Function working in editor but not in build

Post 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.
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Lua Function working in editor but not in build

Post by boz »

Oh wow, I didn't know about that, thank you!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Function working in editor but not in build

Post by Tony Li »

Glad to help!
Post Reply