Changing a C# script variable or calling a function through a Dialogue Node

Announcements, support questions, and discussion for the Dialogue System.
Strig
Posts: 40
Joined: Fri Aug 21, 2020 12:33 pm

Changing a C# script variable or calling a function through a Dialogue Node

Post by Strig »

Hello, I have a variable I want to change in a script in the very first conversation I have with an NPC. As such, I think placing it in the Dialogue Node that ends the conversation would be appropriate, but I couldn't call the NPC object reference in the Unity Event section of the node. is there any way for me to do it?

For reference, this is how my NPC is set up:

- Root
->>> Dialogue
->>>>>> Dialogue Components child - this one has the DS Triggers and the script whose variables need to be changed.
User avatar
Tony Li
Posts: 20744
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Tony Li »

If you add a scene event, can you call it there?
Strig
Posts: 40
Joined: Fri Aug 21, 2020 12:33 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Strig »

Sorry for the late reply.

The Scene Events tab doesn't appear as in the video. All I have is a regular On Execute() tab. My version of Dialogue System is 2.2.6. Were Scene Events added after that?

And on a sidenote, do Scene Events also apply if I'm using Unity's Multi-Scene Editing?
User avatar
Tony Li
Posts: 20744
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Tony Li »

Strig wrote: Wed Mar 24, 2021 9:38 amThe Scene Events tab doesn't appear as in the video. All I have is a regular On Execute() tab. My version of Dialogue System is 2.2.6. Were Scene Events added after that?
Yes, they were added in 2.2.7.
Strig wrote: Wed Mar 24, 2021 9:38 amAnd on a sidenote, do Scene Events also apply if I'm using Unity's Multi-Scene Editing?
They can. When you add a scene event to a dialogue entry node, the dialogue entry node adds a special "Dialogue System Scene Events" GameObject to the active scene if it doesn't already exist. The node will have a unique GUID that identifies a UnityEvent block on the GameObject. So you just need to keep an eye on which scene is active to make sure it adds the GameObject to the right one.
Strig
Posts: 40
Joined: Fri Aug 21, 2020 12:33 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Strig »

So I tried updating the Dialogue System to get the new functions for the Event... and the dialogues just stopped being called.

Do the updates replace the default assets? Maybe they've been reverted to another form.
User avatar
Tony Li
Posts: 20744
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Tony Li »

Hi,

Content made in DS 2.2.6 should run fine in 2.2.15. You can review the release notes to see if anything in particular might affect your project. Usually you can just skip down to the lines that start with "Changed:". They're usually fairly rare. I don't see any that would cause conversations to stop being called.

If you directly modified any Dialogue System files, the update would overwrite your modifications. For coding, the Dialogue System provides a lot of script hooks and virtual methods so you can override behavior with your own scripts instead of directly modifying Dialogue System scripts. For prefabs, it's a good idea to make a copy of any prefabs and customize your copy instead of the original.
Strig
Posts: 40
Joined: Fri Aug 21, 2020 12:33 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Strig »

Well, I checked the prefabs and even changed a few settings, but the issue seems to be with the database, from what I'm guessing, since there are no warnings on the Console.

However, these were appearing in the Dialogue Nodes - specifically the first ones in the conversations.
Captura de Tela (213).png
Captura de Tela (213).png (61.83 KiB) Viewed 444 times
Are these indicative of reference problems? It would explain what's happening, since most of the nodes are set to Block if the conditions aren't met. If they are, how can I fix or at least see what's wrong?
User avatar
Tony Li
Posts: 20744
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Tony Li »

Hi,

Those icons are new.
  • The blue icon tells you the node has a Sequence.
  • The red ? tells you the node has Conditions.
  • The green arrow tells you the node has a Script.
Try clearing the <START> node's Sequence.

If that doesn't fix it, temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. Then play the scene and start a conversation. The Console window will have a trace log of Dialogue System activity. Look for lines such as:

Dialogue System: Starting conversation 'Title'...

And also:

Dialogue System: Add Link <-- shown if a link is currently valid

Dialogue System: Block on False Link <-- shown if a link's Conditions are false
Strig
Posts: 40
Joined: Fri Aug 21, 2020 12:33 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Strig »

Interestingly, I put a Debug Log in the Usable component and it appears in the Console, but there's no log for "Starting conversation". So it kinda looks like the input is registering, but it's not being sent to my Dialogue System Trigger.

It makes no sense why it's happening, though. The database is there, my prefabs seem to be fine. I don't know why it just stopped working like that. Are there any additional conditions for starting conversations between the version I had and the current one?

Additionally, calling "Start Conversation" through an FSM actually starts the conversation as normal, but I can't progress past the first line, as if the input isn't registering in the Dialogue System.
User avatar
Tony Li
Posts: 20744
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing a C# script variable or calling a function through a Dialogue Node

Post by Tony Li »

Are you using Unity's built-in input or the new Input System package or some third party input system?

What's the Sequence on the <START> node, by the way?
Post Reply