Page 1 of 1
C#/Lua functions executed on wrong instance?
Posted: Sat Oct 23, 2021 11:18 am
by dreternal
I have two boxes set up as NPCs (actors). Call them Instance01 and Instace02. If I interact with either one, and call a custom FollowMe() function I have in C#, the method is always called on Instance01 even if I'm only interacting with Instance02.
Lua.RegisterFunction("Follow", this, SymbolExtensions.GetMethodInfo(() => Follow()));
It shows up in my Custom function lists ok, and gets executed, just on the wrong GameObject instance.
Ideas?
Windows 11
Unity 2021.1.7f
Dialog System for Unity 2.2.18
Re: C#/Lua functions executed on wrong instance?
Posted: Sat Oct 23, 2021 1:37 pm
by Tony Li
Hi,
Lua function names are registered globally.
If you run Lua.RegisterFunction("Follow"...) on Instance01, then you can't register it again on Instance02. (In the Console window, you'll see a warning message indicating this.)
You could write your FollowMe function to make the current conversation conversant (e.g., NPC) follow the player. Example:
Code: Select all
Lua.RegisterFunction("FollowMe", this, SymbolExtensions.GetMethodInfo(() => FollowMe()));
...
void FollowMe()
{
YourAIScript npcAI = DialogueManager.currentConversant.GetComponent<YourAIScript>();
npcAI.FollowPlayer();
}
Re: C#/Lua functions executed on wrong instance?
Posted: Sun Oct 24, 2021 5:29 am
by dreternal
Thanks for that. I have modified my code, but apparently, DialogueManager.currentConversant is always returning the same GameObject, no matter who I'm talking to.
Re: C#/Lua functions executed on wrong instance?
Posted: Sun Oct 24, 2021 5:35 am
by dreternal
Screenshot showing that I am interacting with NPC2 but NPC1 is getting methods called.
Re: C#/Lua functions executed on wrong instance?
Posted: Sun Oct 24, 2021 9:08 am
by Tony Li
Hi,
Please see
Character GameObject Assignments.
Check what's assigned to the Dialogue System Trigger's Actions > Start Conversation > Conversation Conversant field, and to the NPCs' Dialogue Actor components (if present).
Then temporarily set the Dialogue Manager's Other Settings > Debug Level to Info and reproduce the issue. When a conversation starts, you should see a line in the Console like this:
Dialogue System: Starting conversation 'title' with actor=X and conversant=Y
Check that 'Y' is the GameObject you intend.