[HOWTO] How To: Not Select Usable If Conditions Are False

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Not Select Usable If Conditions Are False

Post by Tony Li »

Since the Selector/Usable system can be used for anything, not just Dialogue System Triggers, it doesn't natively check if the NPC's Dialogue System Trigger > Conditions are valid. If you want to do this so that it prevents the Selector/Proximity Selector from selecting a Usable whose Dialogue System Trigger > Conditions are false, you can make a subclass. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MyProximitySelector : ProximitySelector
{
    protected override void CheckTriggerEnter(GameObject other)
    {
        if (!enabled || other == null) return;
        var usable = other.GetComponent<Usable>();
        if (usable == null || !usable.enabled) return;
        var dsTrigger = other.GetComponent<DialogueSystemTrigger>();
        if (dsTrigger != null && !(dsTrigger.enabled && dsTrigger.condition.IsTrue(transform))) return;
        base.CheckTriggerEnter(other);
    }
{/code]
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HOWTO] How To: Not Select Usable If Conditions Are False

Post by Tony Li »

If your Dialogue System Trigger is configured to start a conversation, and if you want to also check if the conversation currently has valid entries before showing the usable UI, you can add a check for that.

1. UNtick the Dialogue System Trigger's Actions > Start Conversation > Skip If No Valid Entries.

2. Change the script to:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MyProximitySelector : ProximitySelector
{
    protected override void CheckTriggerEnter(GameObject other)
    {
        if (!enabled || other == null) return;
        var usable = other.GetComponent<Usable>();
        if (usable == null || !usable.enabled) return;
        
        // Check if Dialogue System Trigger's Conditions are true:
        var dsTrigger = other.GetComponent<DialogueSystemTrigger>();
        if (dsTrigger != null && !(dsTrigger.enabled && dsTrigger.condition.IsTrue(transform))) return;
        
        // Check if conversation has valid entries:
        if (!(string.IsNullOrEmpty(dsTrigger.conversation) && DialogueManager.ConversationHasValidEntry(dsTrigger.conversation))) return;
        
        // All checks passed, so show usable UI:
        base.CheckTriggerEnter(other);
    }
}
Post Reply