Page 1 of 1

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

Posted: Wed Jul 03, 2024 7:19 am
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.

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

Posted: Wed Jul 03, 2024 8:14 am
by Tony Li
Hi,

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