Forum rules - please read before posting.

Expressions on Multiple Meshes

The way I have my character set up is with three meshes for the head: Head mesh, Mouth mesh and Eye mesh.

Expressions aren't appearing on either of the meshes. Is there a way to change multiple meshes to the selected expression texture?

Comments

  • How are you using expressions to update the character? And how is your character animated - with Mecanim?

    The texture you supply in the character Inspector is used to update their portrait graphic - not the texture used by any of their meshes. If using Mecanim, you can define an "Expression ID integer" paramter in the character's Inspector and Animator Controller, and use that to alter your character's appearance as their Expression ID changes.

  • edited December 2019

    With the expression ID integer solution. Will the variable name entered in the character NPC component only search the characters animator for the component?
    If so, that might be a problem since I have an animator for each mesh to control blinking and jaw movement.

  • edited December 2019

    Ok, I think I have it figured out. I'm still dense. Using layers I can have them all in one animator.

    However, the animation is still not playing despite changing the expression id integer.

  • However, the animation is still not playing despite changing the expression id integer.

    It'll be down to the way your Animator Controller is set up, in that case. It's not an AC issue.

  • I managed to get the expressions working. Also needed to set a default normal expression as the expression was constantly happy otherwise. However, with the mouth mesh, the expressions int seems to be overriding the lip sync textures so no lip sinc is happening. Is there a way to use lip-syncing with emotions?

  • Correction. The issue was with the animation layer default entry animation not being overridden by the lip-syncing. Not sure how to fix this issue since I assumed that lip-syncing would override any animations with the mouth the same way eye changing would override blinking.

  • How are you displaying lip-syncing? Via the Lip Sync Texture component?

    This updates the texture via an Update call, so there's likely a conflict with updating the Animator at the same time.

    I'd recommend relying on your Phoneme ID parameter to instead update the texture through the Animator in the same was as your Expressions, but you could also try disabling the "expression" Animator layer whenever the character speaks by hooking into the OnStartSpeech / OnStopSpeech events through a script attached to the character:

    using UnityEngine;
    using AC;
    
    public class ToggleExpressionLayer : MonoBehaviour
    {
    
        public int expressionLayerIndex = 1;
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech += StartSpeech;
            EventManager.OnStopSpeech += StopSpeech;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnStartSpeech -= StartSpeech;
            EventManager.OnStopSpeech -= StopSpeech;
        }
    
    
        private void StartSpeech (AC.Char character, string lineText, int lineID)
        {
            if (character == GetComponent <AC.Char>())
            {
                character.GetAnimator ().SetLayerWeight (expressionLayerIndex, 0f);
            }
        }
    
    
        private void StopSpeech (AC.Char character)
        {
            if (character == GetComponent <AC.Char>())
            {
                character.GetAnimator ().SetLayerWeight (expressionLayerIndex, 1f);
            }
        }
    
    }
    
  • Yes, we are using the lip-sync texture.

    The way I am using the animator is to have one layer for the mouth and one layer for the eyes. Using a mask seems to stop blinking on that layer for some reason. Not sure why since they were working two days ago.

    Thanks for the script but it is not working for me. Not sure why, but could be connected to the mask issue.

  • Ok, found the issue. The material keeps deleting its reference for some reason.

  • Does it actually affect the "mouth" layer as it should when the character speaks?

    If things were working before, likely something got changed - I can't offer much in the way of what that might be though.

  • For some reason, the material reference for the animations is missing. Not sure why. Fixing that fixes the blinking but the script doesn't seem to be allowing for lip-syncing. The expression layer is the third layer in the animator, so the index should be 2 right?

  • It does lower the weight, but either doesn't do it fast enough to register or doesn't trigger the lip sync.

  • edited December 2019

    Might be best to stick to using the Phoneme ID parameter instead of the LipSyncTexture component, then.

    However, it may be that if the LipSyncTexture updates the material in LateUpdate, as opposed to Update, then it would override the effect of the Animator. I'll see about adding such an option to the component.

  • Thanks! I'll keep an eye out for the next AC update then!

  • edited January 2020

    Hi Chris. Just tried out the lateupdate to see if it would work.

    I just want to say thank you for including this in the latest update of AC dispute only games with Fear Effect or Grim Fandango style texture graphics will need something like this.

    However, the late update seems to update the mouth mesh to the first Phoneme texture, ignoring the currently playing animation. I've tried combining the late update with the toggle expression layer script, but no combination appears to be working. It seems that the update is working a little too well, and is now overriding everything.

  • Changes made in LateUpdate will always override the effects of an Animator. That's just standard Unity behaviour. This is why my first suggestion was not to rely on this - but to use the "Phoneme ID" integer parameter to update your character solely through the Animator.

    Are you looking to have the LateUpdate only work while the character is talking? You could modify the above ToggleExpressionLayer script to instead change the LipSyncTexture's "affectInLateUpdate" property via the OnStartSpeech / OnStopSpeech events.

  • Yeah, I would need the system to display the animation before and after the lipsync. Right now, it seems to be stopping all animation.

  • This is what I mean, and you'd only need one instance of it in the scene - not one per character:

    using UnityEngine;
    using AC;
    
    public class ToggleLipSyncTextureUpdateMode : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech += StartSpeech;
            EventManager.OnStopSpeech += StopSpeech;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnStartSpeech -= StartSpeech;
            EventManager.OnStopSpeech -= StopSpeech;
        }
    
    
        private void StartSpeech (AC.Char character, string lineText, int lineID)
        {
            if (character)
            {
                LipSyncTexture lipSyncTexture = character.GetComponentInChildren <LipSyncTexture>();
                if (lipSyncTexture) lipSyncTexture.affectInLateUpdate = true;
            }
        }
    
    
        private void StopSpeech (AC.Char character)
        {
            if (character)
            {
                LipSyncTexture lipSyncTexture = character.GetComponentInChildren <LipSyncTexture>();
                if (lipSyncTexture) lipSyncTexture.affectInLateUpdate = false;
            }
        }
    
    }
    
  • It works! Thank you, Chris!

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.