Change node actor dynamically
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Change node actor dynamically
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.
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
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
However, I recommend using it by passing the actor to the conversation from the beginning as described in Character GameObject Assignments
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Re: Change node actor dynamically
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.
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;
}
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Re: Change node actor dynamically
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
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:
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;
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Re: Change node actor dynamically
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.
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
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.
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Re: Change node actor dynamically
I see. Basically I have this C# script
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.
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
Use:
Code: Select all
var current_Node_ID = Lua.Run("return thisID").asInt;
-
- Posts: 41
- Joined: Mon Jul 19, 2021 11:27 am
Re: Change node actor dynamically
That did it ! I never would have thought of getting it that way. Thanks for the help.