Page 1 of 1

Destroying an NPC Object Within Conversation [Solved]

Posted: Sat Mar 31, 2018 1:05 am
by pegassy
Hello,

I am looking for a way to disable or destroy an NPC object during a conversation if a particular conversation option is chosen. I am using Opsive's TPC. Is there a way with or without integration with Opsive's TPC to destroy the NPC object?

Thank you.

Re: Destroying an NPC Object Within Conversation

Posted: Sat Mar 31, 2018 8:56 am
by Tony Li
Hi,

Use the SetActive() sequencer command. For example:
  • Dialogue Text (NPC): "Don't press this button."
    • Dialogue Text: (Player) "[press button]"
    • Sequence:

      Code: Select all

      Audio(Explosion);
      SetActive(Building,false)
If you want to remember in saved games that the Building has been deactivated, use a dialogue database variable and the Persistent Active Data component. For example, add this sequencer command:
  • Dialogue Text (NPC): "Don't press this button."
    • Dialogue Text: (Player) "[press button]"
    • Sequence:

      Code: Select all

      Audio(Explosion);
      SetActive(Building,false);
      SetVariable(DestroyedBuilding,true)
and then configure the Persistent Active Data component with the following values:
  • Target: Building
  • Condition > Lua Conditions: Variable["DestroyedBuilding"] == true

Re: Destroying an NPC Object Within Conversation

Posted: Sat Mar 31, 2018 9:05 am
by Eldinen
You can use SendMessage(DestroyGameObject,,yourObject) then the gameobject yourObject must have a script with a method DestroyGameObject like this:

https://docs.unity3d.com/ScriptReferenc ... stroy.html

This destroy the gameobject, you cannot recovery it

Re: Destroying an NPC Object Within Conversation

Posted: Fri Apr 06, 2018 11:39 pm
by pegassy
Thank you for the super helpful posts. I will try it. This is opens up many possibilities from within the dialogues!

Re: Destroying an NPC Object Within Conversation

Posted: Fri Apr 06, 2018 11:43 pm
by pegassy
It worked like a charm. Thanks a lot.

Re: Destroying an NPC Object Within Conversation [Solved]

Posted: Sat Apr 07, 2018 8:07 am
by Tony Li
Glad to help!