Changing the "Use message" at runtime.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
GiantDad
Posts: 5
Joined: Fri Apr 19, 2024 2:08 am

Changing the "Use message" at runtime.

Post by GiantDad »

Hey there,

I'm trying to have my player's ProximitySelector's use message change based on the current input scheme being used. I'm using TextMeshPro's rich text system to incorporate sprites into the use message to show keyboard/controller buttons.

I have no issues setting the use message through the player's ProximitySelector component at Start(), but changing the "defaultUseMessage" after this seems to do nothing. I can only guess this is due to an external component taking the reins after receiving this value at the start.

Just wondering if there's a clean way I can change the use message through script at runtime.

Thanks so much for your time!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing the "Use message" at runtime.

Post by Tony Li »

Hi,

The SelectorUseStandardUIElements component caches the use message. After changing the use message at runtime, call the SelectorUseStandardUIElements's ConnectDelegates() to update the use message. Here's an example script that changes the use message to "USE: <Space>" when you press [F1]:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

[RequireComponent(typeof(Selector))]
[RequireComponent(typeof(SelectorUseStandardUIElements))]
public class ChangeUseMessage : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            GetComponent<Selector>().defaultUseMessage = "USE: <Space>";
            GetComponent<SelectorUseStandardUIElements>().ConnectDelegates();
        }
    }
}
GiantDad
Posts: 5
Joined: Fri Apr 19, 2024 2:08 am

Re: Changing the "Use message" at runtime.

Post by GiantDad »

Hi Tony,

Thank you so much! This is exactly what I needed! As always, you're at the top of your game!

I appreciate the help and hope you have a good one!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing the "Use message" at runtime.

Post by Tony Li »

Glad to help!
Post Reply