Hey, I'm trying to figure something out.
I have a Corgi character with 2 "Jump" components - one is a single jump and the other a double jump. I also have a "Double Jump Item", which is actually just an NPC.
I would like to use a Dialogue System Trigger (on conversation end) to Enable/Disable the jump components. But I'm aware that it won't work to have the trigger pointing to the player prefab, since it instantiates a copy of the prefab.
I guess the solution would be to have the trigger within the player prefab. But I'm not quite sure the best way to set this up, since it needs to only work with this particular NPC. Any help is appreciated (:
Using a Dialogue System Trigger to switch player components on/off
-
- Posts: 194
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Using a Dialogue System Trigger to switch player components on/off
Please correct me if I'm misunderstanding you. Do you want to enable the character's double jump ability after talking to the actor "Double Jump Item"?
If so, then since the player is instantiated at runtime, a good solution would be to use a sequencer command. Try this: In your player prefab, disable the double jump ability component. In the conversation, use this Sequence on the one of the NPC's nodes:
where CharacterDoubleJump is the name of the ability. I'm assuming that, since the NPC is the speaker (i.e., node's actor), the player is the listener (i.e., node's conversant). I included {{default}} to make sure the node also plays the default sequence. This is optional.
Alternatively, keep the double jump ability component enabled, but keep the Ability Permitted checkbox unticked. Write a custom sequencer command -- perhaps called PermitAbility() -- to call the ability's PermitAbility() method. Then you'd set the node's Sequence to something like:
If you're using the save system, you might also want to save the fact that the player has talked to the NPC and acquired double jump. Save this in a Dialogue System variable. Add a Dialogue System Trigger to the player prefab. Set it to OnStart. Set the Condition to check the variable. Set Actions > OnExecute() event to tick the AbilityPermitted checkbox.
If so, then since the player is instantiated at runtime, a good solution would be to use a sequencer command. Try this: In your player prefab, disable the double jump ability component. In the conversation, use this Sequence on the one of the NPC's nodes:
Code: Select all
SetEnabled(CharacterDoubleJump,true,listener); {{default}}
Alternatively, keep the double jump ability component enabled, but keep the Ability Permitted checkbox unticked. Write a custom sequencer command -- perhaps called PermitAbility() -- to call the ability's PermitAbility() method. Then you'd set the node's Sequence to something like:
Code: Select all
PermitAbility(CharacterDoubleJump,true,listener); {{default}}
Re: Using a Dialogue System Trigger to switch player components on/off
Here's the PermitAbility() sequencer command. I'll also include it in the next Corgi integration package.
SequencerCommandPermitAbility.cs
SequencerCommandPermitAbility.cs
Code: Select all
using UnityEngine;
using MoreMountains.CorgiEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandPermitAbility : SequencerCommand
{
public void Awake()
{
var abilityName = GetParameter(0);
var value = GetParameterAsBool(1);
var subject = GetSubject(2, speaker);
var character = (subject != null) ? subject.GetComponent<Character>() : null;
var ability = (character != null) ? subject.GetComponent(abilityName) as CharacterAbility : null;
if (character == null)
{
if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: PermitAbility(" + GetParameters() + "): Can't find subject or Character on subject.");
}
else if (ability == null)
{
if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: PermitAbility(" + GetParameters() + "): Can't find ability " + abilityName + " on " + subject + ".", subject);
}
else
{
if (DialogueDebug.logInfo) Debug.Log("Dialogue System: Sequencer: PermitAbility(" + ability + ", " + value + ", " + subject + ")", subject);
ability.PermitAbility(value);
}
Stop();
}
}
}
-
- Posts: 194
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Using a Dialogue System Trigger to switch player components on/off
Thanks so much, this looks like exactly what I need.