Any way to include icons or images/sprites in Use Message?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mcfurgerburger
Posts: 12
Joined: Thu May 26, 2022 11:33 am

Any way to include icons or images/sprites in Use Message?

Post by mcfurgerburger »

The use message is nice because it pops up when a player is in range of a usable object.

I'd like to be able to display icons along with text, so I can indicate for the player to say, press a certain button on the gamepad in order to interact.

I'd also like to be able to detect if the player is using a gamepad (and what kind of gamepad) or keyboard/mouse and to be able to adjust the message accordingly.

I wasn't able to find any documentation or examples on this so I am wondering if there is a solution for it that anyone has thought of.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Any way to include icons or images/sprites in Use Message?

Post by Tony Li »

Hi,

Use TextMesh Pro and <sprite> tags. (See: TextMesh Pro Support)

Bonus: You can also use [var=variable] tags in the text — for example, to conditionally use different sprites based on what type of controller the player is using.
mcfurgerburger
Posts: 12
Joined: Thu May 26, 2022 11:33 am

Re: Any way to include icons or images/sprites in Use Message?

Post by mcfurgerburger »

How do I define the sprite asset that proximity selector or usable uses?

edit: I changed the TMP settings to use the sprite asset I want, however doing something like

<sprite index=1> in the Use message does not show the sprite, it just shows that text instead.

Also I can't use standard ui selector elements because the Use message Text takes in a Text object, not a TextMeshPro object.

Do you have a working example of using sprites in the Use Message?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Any way to include icons or images/sprites in Use Message?

Post by Tony Li »

mcfurgerburger wrote: Tue May 31, 2022 4:46 pmHow do I define the sprite asset that proximity selector or usable uses?

edit: I changed the TMP settings to use the sprite asset I want, however doing something like

<sprite index=1> in the Use message does not show the sprite, it just shows that text instead.
The syntax is: <sprite=1> or <sprite name="name">
mcfurgerburger wrote: Tue May 31, 2022 4:46 pmAlso I can't use standard ui selector elements because the Use message Text takes in a Text object, not a TextMeshPro object.
Enable TextMesh Pro Support.
mcfurgerburger wrote: Tue May 31, 2022 4:46 pmDo you have a working example of using sprites in the Use Message?
Here you go:

DS_SelectorUI_TMProSpriteExample_2022-05-31a.unitypackage

The example assumes that you've ticked the Dialogue System Welcome Window's TMP_PRESENT checkbox.
mcfurgerburger
Posts: 12
Joined: Thu May 26, 2022 11:33 am

Re: Any way to include icons or images/sprites in Use Message?

Post by mcfurgerburger »

Enabled TMP support and changed the use message to <sprite=1> and it still does not work...

I will look at the sample project but this is really frustrating. considering TMP comes included by default in Unity now, you should consider enabling TMP support from the getgo as well.

edit: the example package you linked doesn't work because of missing Prefabs. I did reimport so not sure what is going on.

edit: I mean, I am able to use TMP UGUI elements now but it simply doesn't do anything. Attaching screenshots of how I have it set up. With the following setup I don't even get anything to appear when I go up to a usable object now (although it is still usable).
Attachments
screen1.png
screen1.png (38.39 KiB) Viewed 1925 times
screen2.png
screen2.png (40.93 KiB) Viewed 1925 times
screen3.png
screen3.png (100.53 KiB) Viewed 1925 times
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Any way to include icons or images/sprites in Use Message?

Post by Tony Li »

Hi,

When importing version 2.2.28+, it will ask if you want to enable TextMesh Pro support.

The example scene was exported from Unity 2021 and is based on the Dialogue System's DemoScene1 scene. If you've removed the demo assets, the scene will report missing prefabs.

I just updated the example scene so the player's Selector Use Standard UI Elements component uses a Layer-Specific Element for the Terminal GameObject:

DS_SelectorUI_TMProSpriteExample_2022-05-31a.unitypackage

In your own scene, make sure the Dialogue Manager's Instantiate Prefabs component isn't also instantiating a default selector UI. In the example scene above, I removed the default selector UI prefab from the component's Prefabs list since my custom TextMesh Pro selector UI is in the scene as a child of the Dialogue Manager.
mcfurgerburger
Posts: 12
Joined: Thu May 26, 2022 11:33 am

Re: Any way to include icons or images/sprites in Use Message?

Post by mcfurgerburger »

Just now getting back to this. I have your demo scene working in my new project.

It shows sprites in use messages and everything.

However when I try it in my own scene, it does not.

What did you do to make sure it is pointing to the sprite asset?? I couldn't find any reference to it in any of the scene's objects.

edit: after much digging I finally figured it out.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Any way to include icons or images/sprites in Use Message?

Post by Tony Li »

I should've mentioned that, to keep the example small, I just used the default sprite asset included with TMPro. You can assign your own sprite asset to each TextMeshProUGUI's Extra Settings section, or assign it globally in TMPro's settings asset.
mcfurgerburger
Posts: 12
Joined: Thu May 26, 2022 11:33 am

Re: Any way to include icons or images/sprites in Use Message?

Post by mcfurgerburger »

Yeah there were several steps that I had to figure out. I fault Unity mostly for not documenting the new input system well.

I also did not know that adding the selector UI message panel to dialoguesystem overwrites the default, so that was good to know.
Post Reply