dialogue database in dialogue actor component keeps getting set to null

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
musicROCKS013
Posts: 9
Joined: Fri Jan 03, 2025 8:29 pm

dialogue database in dialogue actor component keeps getting set to null

Post by musicROCKS013 »

I have an object with a "Dialogue Actor" component on it, and I keep getting a null reference exception error here.

Code: Select all


protected virtual void OnEnable()
{
    if (string.IsNullOrEmpty(actor)) return;
    CharacterInfo.RegisterActorTransform(actor, transform); // this is where the error occurs (line 155-ish)
}

The name of the actor matches in the dialogue database and the transform isn't null or anything.

For some reason the "Dialogue Database" field of the Dialogue Actor component keeps getting reset to null for some reason. Even if I have it set to the one that I want, when I press play, it resets to "none," and stays like that even after going back into edit mode. It's also worth noting that the object with the component is a prefab (which has the component) and it is also inside of another component which exists in the scene. I have made sure that there are no overrides that make it null. Another thing that's weird is that whenever I click on one of the prefabs - which has the Dialogue Database field properly created - it fixes the instance... at least until I enter play mode, which is when it is set back to "none" again.

No idea if the Dialogue Database field is even relevant to the issue, probably best to mention though.

Thanks! :D
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: dialogue database in dialogue actor component keeps getting set to null

Post by Tony Li »

Hi,

The Dialogue Database field isn't relevant. It's only used to populate the Actor dropdown in the inspector. The Dialogue Actor component doesn't save a reference to the dialogue database itself. If you've already selected the actor, it doesn't matter if the Dialogue Database field is assigned.

If you inspect that actor in the Dialogue Editor window, do its Portrait Textures and Portrait Sprites lists look okay? Common configurations are that both lists are empty (if you don't use portrait images), or one or more sprites are assigned to Portrait Sprites. (Portrait Textures is for backward compatibility with older Unity versions.)
musicROCKS013
Posts: 9
Joined: Fri Jan 03, 2025 8:29 pm

Re: dialogue database in dialogue actor component keeps getting set to null

Post by musicROCKS013 »

Thanks! I was worried because it was acting a bit weird, the reference to the Dialogue Database is just there to make it easier to get a reference to the actor name. (Really great QOL feature btw, this asset is stellar :D )

The real issue is the error I'm getting. It's working fine, I just get an error when I enter play mode, and it only occurs once each time at the beginning of when I enter playmode.

For some reason I'm getting a NullReferenceException Error here :!:

Code: Select all

NullReferenceException: Object reference not set to an instance of an object
PixelCrushers.DialogueSystem.CharacterInfo.RegisterActorTransform (System.String actorName, UnityEngine.Transform actorTransform) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Shared/CharacterInfo.cs:237)
PixelCrushers.DialogueSystem.DialogueActor.OnEnable () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Actor/DialogueActor.cs:156)

Code: Select all

        protected virtual void OnEnable()
        {
            if (string.IsNullOrEmpty(actor)) return;
            Debug.Log(transform + ", " + actor); // ADDED BY ME
            CharacterInfo.RegisterActorTransform(actor, transform); // <- ERROR OCCURS HERE
        }
        
The debug.log shows that neither the transform nor the actor are null (and they both seem correct).

Code: Select all

 public static void RegisterActorTransform(string actorName, Transform actorTransform)
{
            // [...]
            Debug.Log(DialogueManager.masterDatabase + ", " + actorName); // ADDED BY ME
            var actor = DialogueManager.masterDatabase.GetActor(actorName); // <- ERROR OCCURS HERE
            // [...]
 }
This debug.log shows that the DialogueManager.masterDatabase is null. This is likely the origin of the problem, but I don't really know what that is or what might be causing it to be null.

Thanks!
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: dialogue database in dialogue actor component keeps getting set to null

Post by Tony Li »

Hi,

Does your scene have a Dialogue Manager GameObject? You can either place an instance of your Dialogue Manager prefab in the scene, or come from a scene that has a Dialogue Manager GameObject. (By default the Dialogue Manager survives scene changes.)
musicROCKS013
Posts: 9
Joined: Fri Jan 03, 2025 8:29 pm

Re: dialogue database in dialogue actor component keeps getting set to null

Post by musicROCKS013 »

Haha ohhh that's the issue :lol:

I have it where the dialogue manager is instantiated as a prefab by another object (but that probably happens after the error triggers) so it results in it being null! :roll:

Haha thanks so much I can't believe I didn't think of that :D

Edit: I was able to fix the issue by running the instantiation in OnEnable() and setting the script execution to be before the dialogue system's (edit > project settings > script execution order)
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: dialogue database in dialogue actor component keeps getting set to null

Post by Tony Li »

Sounds good. The next update will report a clearer error message if no Dialogue Manager is present when a Dialogue Actor attempts to register itself.
Post Reply