Change node actor dynamically

Announcements, support questions, and discussion for the Dialogue System.
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Change node actor dynamically

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

Re: Change node actor dynamically

Post 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
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Change node actor dynamically

Post 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;
    }
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Change node actor dynamically

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

Re: Change node actor dynamically

Post 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;
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Change node actor dynamically

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

Re: Change node actor dynamically

Post 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.
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Change node actor dynamically

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

Re: Change node actor dynamically

Post by Tony Li »

Use:

Code: Select all

var current_Node_ID = Lua.Run("return thisID").asInt;
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Change node actor dynamically

Post by thecodehermit »

That did it ! I never would have thought of getting it that way. Thanks for the help.
Post Reply