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!
Get Actor Portrait
Re: Get Actor Portrait
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:
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:
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();
}
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();
}
}
}