Forum rules - please read before posting.

Showing a Portrait and associating a speaker for Conversations/Dialog

edited February 13 in Technical Q&A

Hi

Newish AC user; experienced programmer/game dev. Forgive any terminology or not knowing about systems. I've been reading docs but am far from a AC expert.

AC Version: 1.79.3

Goal: We would like a portrait to display during both subtitles and conversations (dialog). The former was added easily enough following the documentation.

Steps Taken for Conversations

  • Add custom menu (PortraitTest) as suggested by Chris here. Manual appear and enabled by default to test.
  • Menu has a Graphic element.
  • Graphic type set to Dialogue Portrait. The Linked Image references the Image GO in the UI prefab (using Unity UI).

The above "works" with speech. The image is updated for the correct character for each line. (Kudos for this system, its done well).

Problem: Conversations (Dialog) don't have any association about who is speaking (which Chris says here . So when a Start Conversation event is triggered there is no associated person "speaking" those dialog options. And, the last person speaking isn't always valid as this is a common case:

  1. NPC speaks (portrait is correctly set to them)
  2. Conversation starts - which is the main player responding the the NPC with several dialog options.
  3. Since no portrait has been set for the main player the last portrait (NPC) is displayed. This isnt correct.
    Triggering a Dialog -> Change Portrait event before the Conversation wont (afaik) work because we want to use the current main players portrait NOT force to a specific one.

Idea

  • Add a script to the Image GO in the PortraitTestUI prefab (made above).
  • Listen for the OnConversationStart event
  • But: The Conversation object passed to that event has no association with who is speaking
  • So: Add a AC.Char variable to the Conversation class so that we can set the current character who is saying this dialog.
  • In the OnConversationStart event, set the Image to be the portrait of who this dialog is associated with.

Is this a reasonable approach? Any other suggestions?

Images:

Menu: https://ibb.co/pzzxqRk
Menu Element: https://ibb.co/BwNnvhM
(Note: While the Linked Image shows as "Missing" it is still linked as it updates correctly. I assume this is a bug, since its referencing a prefab?

Comments

  • Welcome to the community, @Phantasie.

    Apologies for your post being temporarily hidden - it was mistakenly auto-flagged as spam, but I've verified your account so it shouldn't happen again.

    It's best to avoid editing AC's core scripts. Rather than adding a Char variable to Conversation (and also updating ConversationEditor to display it), you can attach a new C# script that has the variable stored, and then use GetComponent in the event to extract it.

    You could also merge the OnConversationStart event call into this same script.

    The MenuGraphic element has a PortraitCharacterOverride property that - when set - will override the default behaviour of showing its associated speech character. What you could try is assign the custom character when the conversation begins, and then clear this override when an option is chosen.

    Something like this, attached to a Conversation, should do it:

    using UnityEngine;
    using AC;
    
    public class ConversationPortrait : MonoBehaviour
    {
    
        public AC.Char myCharacter;
    
        void OnEnable ()
        {
            EventManager.OnStartConversation += OnStartConversation;
            EventManager.OnClickConversation += OnClickConversation;
        }
    
        void OnDisable ()
        {
            EventManager.OnStartConversation -= OnStartConversation;
            EventManager.OnClickConversation -= OnClickConversation;
        }
    
        void OnStartConversation (Conversation conversation)
        {
            if (conversation.gameObject == gameObject)
            {
                (PlayerMenus.GetElementWithName ("PortraitTest", "Portrait Image") as MenuGraphic).PortraitCharacterOverride = myCharacter;
            }
        }
    
        void OnClickConversation (Conversation conversation, int optionID)
        {
            if (conversation.gameObject == gameObject)
            {
                (PlayerMenus.GetElementWithName ("PortraitTest", "Portrait Image") as MenuGraphic).PortraitCharacterOverride = null;
            }
        }
    
    }
    

    While the Linked Image shows as "Missing" it is still linked as it updates correctly. I assume this is a bug, since its referencing a prefab?

    It's actually the Constant ID that the Menu uses to keep track of the linked UI object, with the Editor's Linked Image field only used to initially assign it. Though, the upcoming v1.80 update will keep the field assigned, it annoyed me as well.

  • Hi

    Yes, I saw it was hidden. I assumed it was because I edited it. I was going to wait until today to DM you. Thank you :)

    It's best to avoid editing AC's core scripts.

    Agree 100%. Your solution makes much more sense and avoids merge conflicts in the future. I was unaware of PlayerMenus.GetElementWithName which makes this much easier.

    This will also solve a different problem - the ConversationStarted event was fired before the Portrait UI was enabled - and it the Enable function in that class is what subscribed to the event in the first place - meaning it didn't get it. Many ways to fix, but felt wrong.

    Ill try what you said today and follow up if any issues.

    Thanks for the detailed response.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.