Add a dialogue system trigger in code and start a conversation onuse

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
McSwan
Posts: 7
Joined: Sat Jun 24, 2023 2:21 am

Add a dialogue system trigger in code and start a conversation onuse

Post by McSwan »

Add a dialogue system trigger in code and start a conversation onuse.

I have a random npc character the is generated through code (at runtime), so I need to add a dialoguesystemtrigger , as a component at runtime.

eg.

Code: Select all

 if (addDialogueSystemTriggers)
        { 
            DialogueSystemTrigger dialogueSystemTrigger = BaseCharacterInstance.AddComponent<DialogueSystemTrigger>();
            if (Godject.Instance.simplePlayerController != null)
            {
                dialogueSystemTrigger.conversationActor = Godject.Instance.simplePlayerController.transform;
            }
            dialogueSystemTrigger.conversationConversant = BaseCharacterInstance.transform;
            dialogueSystemTrigger.conversation = conversation;

            Usable usable = BaseCharacterInstance.AddComponent<Usable>();
            usable.maxUseDistance = 2.0f;

            DialogueSystemEvents dialogueSystemEvent = BaseCharacterInstance.AddComponent<DialogueSystemEvents>();
        }

But I'm not sure how to add a "start conversation" action in code.
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add a dialogue system trigger in code and start a conversation onuse

Post by Tony Li »

Hi,

If the "conversation" property is set, the Dialogue System Trigger will start the conversation.
Post Reply