Page 1 of 1

SpeakerInfo portrait null for some team members

Posted: Wed Oct 04, 2023 5:53 pm
by kimosabe
I'm using the dialogueEvents in C# to do some custom portrait animation when lines are delivered using:

Code: Select all

dialogueEvents.conversationEvents.onConversationLine.AddListener(LineDelivered);

Code: Select all

public void LineDelivered(Subtitle subtitle)
    {
        if (subtitle.speakerInfo.portrait != null)
        {
            
        }

    }
Which works perfectly on my computer, the problem is that on some of the team member's computers they speakerInfo.portrait is null when this event is called.

I figure it has something to do with async loading (we use large detailed portrait sprites).

We managed prevent this issue by calling:

Code: Select all

{{default}};
SetPortrait(FirstNPC, pic=1);
SetPortrait(SecondNPC, pic=1);
In the sequence of the start node for every conversation, but that's going to be a huge problem if we start adding more NPC portraits, we have need to go through all dialogue again to add these.

(The reason we use SetPortrait is that NPC have different expression portraits we need to change for each line. which works great!)

Is there another solution for this problem?

Thanks in advance for your time!

Re: SpeakerInfo portrait null for some team members

Posted: Wed Oct 04, 2023 9:22 pm
by Tony Li
Hi,

If you're using SetPortrait(FirstNPC, pic=1), this means it's using a portrait image from the actor's portrait list in the dialogue database. When the Dialogue Manager starts, it loads the dialogue database into memory. Since the dialogue database references the portrait images, they should also be loaded into memory at start. There shouldn't be any async loading.

This may not be relevant to your goals, but it is possible to configure the portraits so they're not all loaded when the Dialogue Manager starts. To do this, you'd put the portraits in a Resources folder, asset bundle, or make them addressable assets. Then use SetPortrait(FirstNPC, filename) to load and use the portrait image. (Note: If you use addressables, they could load asynchronously, meaning they might appear after a delay.)

To address your issue, is it possible that something is setting the actors to use another portrait image, not pic=1?

Alternatively, if you want to make sure the portraits are loaded, you could check them when the Dialogue Manager starts. For example, put a script similar to this on the Dialogue Manager:

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CheckPortraits : MonoBehaviour
{
    IEnumerator Start()
    {
        while (!DialogueManager.instance.isInitialized) yield return null;
        foreach (var actor in DialogueManager.masterDatabase.actors)
        {
            var actorName = actor.Name;
            if (actor.spritePortrait != null)
            {
                Debug.Log($"{actorName} pic 1 is {actor.spritePortrait.name}");
            }
            for (int i = 0; i < actor.spritePortraits.Count; i++)
            {
                if (actor.spritePortraits[i] != null)
                {
                    Debug.Log($"{actorName} pic {i+2} is {actor.spritePortraits[i].name}");
                }
            }
        }
    }
}

Re: SpeakerInfo portrait null for some team members

Posted: Thu Oct 05, 2023 7:24 am
by kimosabe
Thank you for your reply!

That's a great tip on the addressables I didn't know that was possible. Right now they take up a lot of RAM so loading them later on demand would be great for us.

As for the portrait issue, we switch between portraits in dialogue in the sequence of certain nodes. The goal is to have the actors change expressions by changing their portraits. The weird thing is that it works on my PC, and not for somebody else. We use GIT and have the exact same version of the DialogueDatabase.

So on my system the subtitle.speakerInfo.portrait is not null and thus working great, with the correct expression. But for others it is null.

I've added in your debug code snippet and going to ask my teammembers to check on their end.

Re: SpeakerInfo portrait null for some team members

Posted: Thu Oct 05, 2023 9:17 am
by Tony Li
Please also ask your teammates if there are any errors or warnings in the Console window when they play in the editor's play mode.

They can also open the dialogue database in the Dialogue Editor and check that the portraits are properly assigned. Maybe something in the way version control is set up is causing the portraits to become unassigned from the actors -- although that wouldn't really explain why SetPortrait(NPC, pic=1) works.