Forum rules - please read before posting.

action list action for expression change

Hi, I'm trying to create an action to change the expressions, since the speech actions with expressions only start some mouth moving.
How do I get the expression enum list for a dropdown list so I wouldn't need to set the strings and remove human errors?

Comments

  • edited May 2021

    There's no expression enum - expressions are defined per-character, so you need to know which character you're affecting before you can extract their available expressions.

    To expose a dropdown list, you'll want to use Unity's EditorGUILayout.PopUp function, which requires a string array of the various options. You can get such an array for a particular character with this function:

    string[] GetExpressionLabels (AC.Char character)
    {
        List<string> labelsList = new List<string>();
        foreach (Expression expression in character.expressions)
        {
            labelsList.Add (expression.label);
        }
        return labelsList.ToArray ();
    }
    
  • edited May 2021

    I did this:

    `
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;

    if UNITY_EDITOR

    using UnityEditor;

    endif

    [System.Serializable]
    public class MakeExpression : Action
    {
    public override ActionCategory Category { get { return ActionCategory.Custom; }}
    public override string Title { get { return "Show expression"; }}
    public override string Description { get { return "Makes expression to a character."; }}

    public bool isPlayer;
    public Char character;
    public int expressionID;
    
    override public float Run ()
    {
        if (character)
        {
            character.SetExpression (expressionID);
        }
        return 0f;
    }
    
    #if UNITY_EDITOR
    override public void ShowGUI ()
    {
        character = (Char) EditorGUILayout.ObjectField ("Charater:", character, typeof (Char), true);
    
        if (character)
            expressionID = EditorGUILayout.Popup ("Expression:", expressionID, GetExpressionLabels(character));
    }
    #endif
    
    string[] GetExpressionLabels (AC.Char character)
    {
        List<string> labelsList = new List<string>();
        foreach (Expression expression in character.expressions)
        {
            labelsList.Add (expression.label);
        }
        return labelsList.ToArray ();
    }
    

    }`

    It works fine, but now I started to wonder if I could add also a sound - like a little laugh or cough. Since they are connected to a person also like speech, would it be possible - or feasible - to try to combine them to one Action?

  • You could add an AudioClip variable, exposed in ShowGUI, and then played via character.AudioSource.PlayOneShot in Run.

    However, if you're looking to have the same expression type result in the same audio (even if only per-character), then it'd be better to automate it through events.

    There isn't currently an event for when a character changes expression, but I shall look to include this as part of the upcoming 1.73.7 update. Bump this thread after the release if you're interested, and I'll post a sample script.

  • I notice that this script no longer works since I started using Timelines. It seems to capture the character in play. Is there anything I could do?

  • edited June 2021

    If you're using Timeline, you can either create a separate animation layer for a character to handle facial animation/expressions, or create Speech tracks that contain [expression:ID] tags.

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.