Page 1 of 2
Change node actor dynamically
Posted: Sat May 06, 2023 1:04 am
by thecodehermit
Hi
Is it possible to change a conversation node actor dynamically ? For example I start a conversation and in node 1 I run a script that changes the actor of node 15 to something else.
Re: Change node actor dynamically
Posted: Sat May 06, 2023 7:53 am
by Tony Li
Technically you can do it in code by changing the values of the variables in
DialogueManager.currentModel.conversantInfo.
However, I recommend using it by passing the actor to the conversation from the beginning as described in
Character GameObject Assignments
Re: Change node actor dynamically
Posted: Sat May 06, 2023 4:54 pm
by thecodehermit
I didn't really understand what you meant by both of those... But I did manage to almost make it with the code bellow.
That function is registered with Lua and I set it on a specific node and it changes the actor name when the node runs.
The only thing I need is to somehow get the current_Node_ID. Or to somehow get the node from which the script is running.
Code: Select all
public void Test_Lua() {
var database = DialogueManager.masterDatabase;
var conversation = database.GetConversation(DialogueManager.lastConversationID);
var current_Node_ID = 26;
var entry_Node = database.GetDialogueEntry(conversation.id, current_Node_ID);
entry_Node.ActorID = 3;
}
Re: Change node actor dynamically
Posted: Sat May 06, 2023 6:43 pm
by thecodehermit
I found this, but it always gives the node ID of the previous node.... Hopefully you know easy way to get the current node ID, because for the life of me I cant find any way to get it
Code: Select all
DialogueManager.CurrentConversationState.subtitle.dialogueEntry.id;
Re: Change node actor dynamically
Posted: Sat May 06, 2023 7:34 pm
by Tony Li
I re-read your original question and understand it better now. Sorry for my misunderstanding. Try this:
1. Tick the Dialogue Manager GameObject's Other Settings > Instantiate Database. This tells the Dialogue System to create an in-memory copy of the dialogue database when starting, so your code can change it at runtime without affecting the original asset.
2. In node 1, use C# code like this:
Code: Select all
var node15 = DialogueManager.masterDatabase.GetDialogueEntry(DialogueManager.lastConversationID, 15);
var actor = DialogueManager.masterDatabase.GetActor("Some Other Actor");
node15.ActorID = actor.id;
Re: Change node actor dynamically
Posted: Sat May 06, 2023 7:43 pm
by thecodehermit
No problem.
I will do 1. As for 2 will it be possible to get the current node id ? So I can put a script in each node and it will change the current node actor.
Re: Change node actor dynamically
Posted: Sat May 06, 2023 7:55 pm
by Tony Li
If you're already on the current node, it's probably too late to change the current node's actor ID. But you could do it in an OnConversationLine method or in a regular C# method that's registered with Lua, in which case you can use it in a node's Script field. Sorry for being vague. If you can provide more concrete details on what you want to do, I can provide a more detailed/accurate answer.
Re: Change node actor dynamically
Posted: Sat May 06, 2023 8:23 pm
by thecodehermit
I see. Basically I have this C# script
Code: Select all
public void Test_Lua() {
var database = DialogueManager.masterDatabase;
var conversation = database.GetConversation(DialogueManager.lastConversationID);
var current_Node_ID = 26;
var entry_Node = database.GetDialogueEntry(conversation.id, current_Node_ID);
entry_Node.ActorID = 3;
}
It is Registered with LUA And I run it in the script field of the node I want to change the actor. The only thing I need to figure out is the current_Node_ID var. As is now the script works but only for node 26. I want to make it dynamic so it detects which is the current node and then it will change the actor.
Re: Change node actor dynamically
Posted: Sat May 06, 2023 9:15 pm
by Tony Li
Use:
Code: Select all
var current_Node_ID = Lua.Run("return thisID").asInt;
Re: Change node actor dynamically
Posted: Sat May 06, 2023 9:55 pm
by thecodehermit
That did it ! I never would have thought of getting it that way. Thanks for the help.