Page 1 of 1

Character portrait sprite reference

Posted: Wed Sep 22, 2021 11:59 pm
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!

Re: Character portrait sprite reference

Posted: Thu Sep 23, 2021 8:38 am
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);

Re: Character portrait sprite reference

Posted: Thu Sep 23, 2021 11:57 am
by hipsterdufus
Awesome, got it! Thank you.

Re: Character portrait sprite reference

Posted: Thu Sep 23, 2021 12:58 pm
by Tony Li
Glad to help!