How to switch between dialogue scenes that share the same array?

Godot Version

4.6.3

Question

I have two different dialog UI boxes that appear depending on whether an NPC or the player is speaking. I originally used a shared script for both, but decided to use separate scripts as they have different functionalities (ex. the player response box has buttons to choose dialogue, while the NPC dialogue box just cycles through text). However, now I realize I’ll have to re-combine them since they will be sharing the same dialogue array (right?). But now I’m confused on how exactly to switch between the boxes as the dialogue progresses.

Both my NPC dialogue box and player response box scenes have exported variables in the Inspector that allow me to quickly input the character portraits, character name, dialogue text, and button choices (see attached, shoutout to GDQuest for the idea here).

My question is, what is the best way to incorporate some sort of functionality where I can switch between the boxes depending on what part of the dialogue array is being shown? And ideally, how can I put that into the Inspector like I have with the other parts of the dialogue boxes?

Happy to provide code or images of the dialogue boxes if that’s necessary. Thank you!

I suggest you to use Custom Resources.

  • Have a Custom Resource called DialogueEntry (instead of an array)
  • DialougeEntry resource would have related variables like character, name:String, overall_choices:Array, current_choice:int (int that shows which overall_choices:Arrayindex is the current choice.

After this, you can create a new DialogueEntry resource for each NPC. You can change all the variables above I mentioned per NPC, you can track the progress and save it on the resource in thecurrent_choice variable

EDIT: With this approach, in theory, you can have only one NPC script that you attach to all of your NPC scenes (assuming you’d save them as a scene, which I suggest also). And then in that NPC script, you can attach the DialogueEntry custom resource for each NPC.

Ah I hadn’t thought about utilizing the NPC script, thank you so much for the idea!! I do use the same script for every NPC. I’ll try this out tomorrow and see how it goes.

You can also add the variables, those I mentioned for Custom Resource, directly in the NPC script. It would work in a similar way. But using a Custom Resource can be more benefitial in long term. But for the initial way of implementing the functions, it wouldn’t matter much.