Page 1 of 1

Get Actor Portrait

Posted: Tue Mar 15, 2022 10:49 pm
by mrklepper
Hi

I am trying to get the actor portrait of a (future) conversation, like so:

DialogueManager.masterDatabase.GetActor(conversation.GetDialogueEntry(1).ActorID).GetPortraitSprite(1).texture)

However, it returns a NullReference Exception.

I have assigned the Portrait to the actor object both as a sprite and texture2d.

The conversation is the right one, as other data loads correctly, such as subtitle.

What am I doing wrong?

Thank you!

Re: Get Actor Portrait

Posted: Tue Mar 15, 2022 11:11 pm
by Tony Li
Hi,

Let's break it down to make it easier to identify which part is causing the NullReferenceException.

First, if you want to get the portrait of the conversation's Conversant (typically the NPC), you can just do this:

Code: Select all

Actor conversant = DialogueManager.masterDatabase.GetActor(conversation.ConversantID);
if (conversant != null)
{
    Sprite sprite = conversant.GetPortraitSprite();
}
If you instead want to get the portrait of whoever speaks the first node of the conversation (i.e., the node linked from <START>), try this:

Code: Select all

DialogueEntry startEntry = conversation.GetFirstDialogueEntry();
if (startEntry.outgoingLinks.Count > 0)
{
    DialogueEntry firstSpokenEntry = conversation.GetDialogueEntry(startEntry.outgoingLinks[0].destinationDialogueID);
    if (firstSpokenEntry != null)
    {
        Actor speaker = DialogueManager.masterDatabase.GetActor(firstSpokenEntry.ActorID);
        if (speaker != null)
        {
            Sprite sprite = speaker.GetPortraitSprite();
        }
    }
}