How to hide UI selector after use

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VillVarh
Posts: 23
Joined: Mon Nov 06, 2023 5:19 am

How to hide UI selector after use

Post by VillVarh »

Greetings, I'm currently facing an issue with hiding the UI selector in my game. I initiate interactions with objects through the UI selector. Each object is equipped with a usable component, and when I approach them, the UI selector becomes active. Subsequently, clicking the UI selector initiates a conversation. The challenge I'm encountering is that on certain occasions, I initiate a conversation where the object is not part of the dialogue. Consequently, the object doesn't receive its transform in the dialogue system events, preventing me from disabling the usable component through conversation events. Ty. :)
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to hide UI selector after use

Post by Tony Li »

Hi,

Is the Selector / Proximity Selector component on your player GameObject? If so, then is the issue that in these conversations your player GameObject is not the conversation actor or conversation conversant?

If that's the case, here are two ways to handle it:

1. Use the player GameObject as the conversation actor. If your conversation involves two NPCs instead of player-NPC, you can still involve the extra NPC in the conversation when you write it. Just assign that extra NPC as the speaker of some dialogue entry nodes.

2. Or use a small script like this:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class DisableSelectorDuringConversations : MonoBehaviour
{
    void Start() 
    { // These C# events will be invoked regardless of which GameObjects are the primary participants:
        DialogueManager.instance.conversationStarted += OnConversationStarted;
        DialogueManager.instance.conversationEnded += OnConversationEnded;
    }
    void OnDestroy() 
    { 
        DialogueManager.instance.conversationStarted -= OnConversationStarted;
        DialogueManager.instance.conversationEnded -= OnConversationEnded;
    }
    void OnConversationStarted(Transform actor) 
    {
        GetComponent<ProximitySelector>().enabled = false;
    }
    void OnConversationStarted(Transform actor) 
    {
        GetComponent<ProximitySelector>().enabled = true;
    }
}
VillVarh
Posts: 23
Joined: Mon Nov 06, 2023 5:19 am

Re: How to hide UI selector after use

Post by VillVarh »

Currently, my player utilizes a proximity selector and engages in conversations with other NPCs, where the player serves as the actor. The player is equipped with its own dialogue system events component, triggering events during conversations. The challenge I'm facing arises when initiating a conversation, for instance, through a coffee mug. While the coffee mug acts as a conversation trigger, it is neither the actor nor the conversant. My objective is to modify the attributes of the coffee mug after the conversation or at its onset. For example, when I click on the coffee mug, a particle effect is activated, and the UI selector appears on the screen. After the conversation, I aim to deactivate the usable component on the coffee mug along with the particle effect, signaling to the player that it is no longer active. Unfortunately, adding a dialogue system events component to the coffee mug proves ineffective, as it is not a participant in the conversation, rendering the OnConversationStart and OnConversationEnd events ineffectual.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to hide UI selector after use

Post by Tony Li »

Hi,

On the coffee mug, can you use the Dialogue System Trigger's OnExecute() event? Here's an example scene:

DS_CoffeeMugExample_2024-02-27.unitypackage

The coffee mug's Usable component's OnSelect() and OnDeselect() events toggle a point light, which is a stand-in for your particle effect.

The Dialogue System Trigger starts a conversation whose primary actors are Player and an NPC, but the only dialogue entry is assigned to a non-primary actor named Coffee Mug. The Dialogue System Trigger also uses an OnExecute() event to disable the Usable component and turn off the point light.

If you want to remember the Usable component's enabled/disabled state between scene changes and in saved games, add an EnabledSaver component to the coffee mug, assign the Usable component to it, and set a unique Key such as "CoffeMugUsable".
VillVarh
Posts: 23
Joined: Mon Nov 06, 2023 5:19 am

Re: How to hide UI selector after use

Post by VillVarh »

Thank you very much!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to hide UI selector after use

Post by Tony Li »

Glad to help!
Post Reply