Dialogue triggering C# Script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VideoMedicineBear
Posts: 11
Joined: Tue Feb 28, 2023 3:52 pm

Dialogue triggering C# Script

Post by VideoMedicineBear »

Hi. I'm making a 2D game where a conversation with one character triggers that character to follow the player, but only if the conversation ends with a specific line being "spoken." The conversation has a few other endings which shouldn't trigger this C# follow script, and I've been having trouble figuring out how to only enable the C# script on that one ending. Because if it only triggers at the end of the conversation (no matter what the character says) it might not make sense for the story. I'm writing the conversations in Twine and importing through Twison/json. I was thinking maybe there's a code I could write in Twine at the end of that one line that would trigger it but I don't know what code that would be. Can you help me figure out how to do this?
User avatar
Tony Li
Posts: 22131
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue triggering C# Script

Post by Tony Li »

Hi,

In your Twine node text, you can add sections titled "Sequence:", "Conditions:", and/or "Script:". The "Sequence:" section plays cutscene sequencer commands. The Dialogue System has a built-in sequencer command called SetEnabled() that can set a component enabled. Say your follow script on the NPC is named "Follow", and you want to enable it in a node that the NPC speaks. You can set your node's text to something like:

Code: Select all

Alright, I'll follow you.
Sequence:
SetEnabled(Follow, true)
VideoMedicineBear
Posts: 11
Joined: Tue Feb 28, 2023 3:52 pm

Re: Dialogue triggering C# Script

Post by VideoMedicineBear »

Thanks! I am still not able to get it to work. I also have a new problem where the master database is not loading. I'm not sure why this has changed. I get an error that an object reference hasn't been set to instance of object but I haven't been able to find any missing values in my inspector, the Dialogue Manager has the right database assigned to it.
User avatar
Tony Li
Posts: 22131
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue triggering C# Script

Post by Tony Li »

Hi,

Please click on the error and press Ctrl+C to copy its details to the clipboard. Then paste it into a reply.

For the original issue, what does the Unity inspector view of the dialogue entry node look like? The Dialogue Text field should be "Alright, I'll follow you" and the Sequence field should be "SetEnabled(Follow, true)". This Sequence will look for a script named Follow on the dialogue entry node's speaker. If it finds a script with this name, it will set its "enabled" property true.

This may be relevant: Character GameObject Assignments
VideoMedicineBear
Posts: 11
Joined: Tue Feb 28, 2023 3:52 pm

Re: Dialogue triggering C# Script

Post by VideoMedicineBear »

I'm getting this error:
NullReferenceException: Object reference not set to an instance of an object
PixelCrushers.DialogueSystem.DialogueSystemController.get_masterDatabase () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:207)
PixelCrushers.DialogueSystem.DialogueManager.get_masterDatabase () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueManager.cs:63)

Also this error:
Dialogue System: Quest Log couldn't access Lua Item[] table. Has the Dialogue Manager loaded a database yet?
UnityEngine.Debug:LogWarning (object)

Thanks I am trying the new SetEnabled script, as soon as I can get my dialogue database to load.
User avatar
Tony Li
Posts: 22131
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue triggering C# Script

Post by Tony Li »

Hi,

Does your scene have a Dialogue Manager GameObject, and is it active?
VideoMedicineBear
Posts: 11
Joined: Tue Feb 28, 2023 3:52 pm

Re: Dialogue triggering C# Script

Post by VideoMedicineBear »

It does, yes, I think it is active. When a character comes to trigger the dialogue all that comes up is (Selection Name) and it doesn't trigger the dialogue.
User avatar
Tony Li
Posts: 22131
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue triggering C# Script

Post by Tony Li »

That sounds like a selector/proximity selector configuration issue, not an issue with your conversation.

The previous errors suggest that your scene doesn't have an active Dialogue Manager.

Here's an example scene:

DS_FollowExample_2023-03-14.unitypackage

It's a 2D scene that uses Unity's built-in input manager. If you're using a different input system, such as the Input System package, you'll need to set the player settings to use both. It checks the input manager's "Horizontal" input, which is mapped to the A-D keys by default.

The player is a square that you can move by holding A or D. If you approach the NPC (a circle), you can start a conversation. In the conversation, you have an option to tell the NPC to follow you. If you choose this option, its Sequence enables the NPC's follow script.
Post Reply