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
C#/Lua functions executed on wrong instance?
Re: C#/Lua functions executed on wrong instance?
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:
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?
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?
Screenshot showing that I am interacting with NPC2 but NPC1 is getting methods called.
Re: C#/Lua functions executed on wrong instance?
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.
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.