Character portrait sprite reference

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Character portrait sprite reference

Post by hipsterdufus »

Hey there, I am wondering - is there a way to get a reference to an actor's portrait sprite in code? I'd like to get a reference to the sprite so I can use it to populate some dynamic UI. I figure I should be able to ask the dialogue system for this since it's storing everything and I'd rather not create another way to get the sprites. Thank you!
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character portrait sprite reference

Post by Tony Li »

Hi,

If you're talking about the current image being used in a conversation, there are a few ways. You can use an OnConversationLine(Subtitle) method on the Dialogue Manager or either primary participant:

Code: Select all

public void OnConversationLine(Subtitle subtitle)
{
    Debug.Log("Dialogue Text is: " + subtitle.formattedText.text);
    Debug.Log("Speaker's portrait is: " + subtitle.GetSpeakerPortrait());
}
Alternatively, if a conversation is active, you can check DialogueManager.currentConversationState.subtitle:

Code: Select all

if (DialogueManager.isConversationActive)
{
    Debug.Log("Speaker's portrait is: " + DialogueManager.currentConversationState.subtitle.GetSpeakerPortrait());
}
Or you can check the subtitle panel directly:

Code: Select all

Debug.Log("Speaker's portrait is: " + DialogueManager.standardUISubtitlePanel.conversationUIElements.
    defaultNPCSubtitlePanel.portraitImage.sprite);
---

If you just want to get the portrait image(s) of any actor at any time, get the Actor from the DialogueManager.masterDatabase:

Code: Select all

Actor fred = DialogueManager.masterDatabase.GetActor("fred");
Debug.Log("Fred's main portrait is: " + fred.spritePortrait);
Debug.Log("# of alternate portraits: " + fred.spritePortraits.Count);
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Character portrait sprite reference

Post by hipsterdufus »

Awesome, got it! Thank you.
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character portrait sprite reference

Post by Tony Li »

Glad to help!
Post Reply