Forum rules - please read before posting.

'Already Chosen' conversation options

My conversations are rendered through Unity UI. I see there's a setting for Already Chosen color and highlight, but my button colors are set through animations. How can I link the already chosen setting to a new animation?

Comments

  • You'll need to rely on scripting, since the exact effect an option being chosen has will be specific to your needs.

    You can check if a particular option in the currently-active Conversation has been chosen before with:

    AC.KickStarter.playerInput.activeConversation.OptionHasBeenChosen (optionIndex);
    

    Here's a script you can attach to your UI Buttons to update your animation triggers based on this:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class DialogOptionAnimation : MonoBehaviour
    {
    
        public int slotIndex;
        public UnityEngine.UI.Button button;
    
        void OnEnable ()
        {
            Conversation conversation = KickStarter.playerInput.activeConversation;
            if (conversation == null) return;
    
            AnimationTriggers animationTriggers = button.animationTriggers;
            if (conversation.OptionHasBeenChosen (slotIndex))
            {
                animationTriggers.normalTrigger = "NormalChosen";
                // etc
            }
            else
            {
                animationTriggers.normalTrigger = "Normal";
                // etc
            }
            button.animationTriggers = animationTriggers;
        }
    
    }
    

    You'll need to fill in the Inspectors, and it'll need adapting if you have scrolling in your menu.

  • Another question. I tried implementing that script and it mostly works. But when I select an option, when the conversation appears again, the button is in its "normal" state and not its "Already Chosen" state. After I highlight it, it switches to its "Already Chosen" state. How can I make it be in the "Already Chosen" state as soon as it appears?

  • The script should kick in whenever the Conversation appears - check that the Button's Inspector is showing the correct value of "Normal Trigger" in its Animations tab.

    It may be that the Trigger itself needs to be run. Try replacing:

    button.animationTriggers = animationTriggers;
    

    with:

    button.animationTriggers = animationTriggers;
    button.GetComponent<Animator>().SetTrigger (animationTriggers.normalTrigger);
    
  • That works after selecting an option, but there's a small delay. However, it doesn't work at all when starting a new conversation; the options appear in their "Already Chosen" state and stay that way until I highlight them.

  • That works after selecting an option, but there's a small delay.

    This may be down to how the Animator is set up - the script fires the Animator's "Normal Trigger" when updating the field, but what effect this Trigger parameter has will be down to the transitions set up in your Animator.

    Have you created a second "NormalChosen" Trigger parameter and transition in the Animator Controller?

    it doesn't work at all when starting a new conversation; the options appear in their "Already Chosen" state and stay that way until I highlight them.

    Are you referring to options that were previously set to "Already chosen" from the previous Conversation, or do all options set themselves to "Already chosen" regardless of what came before it?

    What are the parameter values set to in a Button component that has this behaviour, at runtime?

  • I ended changing things up. Instead of having different states for the Already Chosen animations, I converted the existing ones to Blend Trees and had the script set the Blend Tree's parameter to 1 and 0 instead.

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.