Forum rules - please read before posting.

Animated 2d textures on 3d model?

My NPCs are 3d (in a 3d game) but features on their faces are 2d. At this point I have static textures as materials for their faces, but will animate them soon. Is the best option to have a video playing on the NPCs as their moving face or is there some way to upload the frames of animation and have Unity swap the the textures in sequence?

Can this be done within the built in Animator component or does AC have a way to deal with this? Need some pointing in the right direction thanks.

Comments

  • It depends on when/how you want to animate them.

    AC has a Lip Sync Texture component that can be used in conjunction with its lip-syncing process to replace a material's texture based on the current phoneme frame. Details of this can be found in the "Constructing animations" section of the Manual's "Lip syncing" chapter.

    Outside of that, AC wouldn't be involved. Which texture is assigned to a material isn't a property that can be directly animated - custom scripting is necessary.

    Having a Material rely on a Video Player to animate its texture however, should be possible without scripting - but that's through the use of Unity-only components.

  • Ok thanks. I'll investigate the Lip Syncing part of AC.

    Are videos on polygons expensive (processing-wise) if I had lots of them?

  • And is there something for idle animations of textures, just ongoing expression changes?

  • No - it's only when handling lip-syncing.

    If your situation is less to do with that, and more about animating them this way generally, then I'd recommend leaving out AC and opting for a Unity-only solution.

    I couldn't say how expensive the tecnique would be - it's too open ended and dealing with how Unity works under the hood. Though, if you were scripting the behaviour manually, you could do things like e.g. disable the effect when an NPC is a certain distance away from the Camera. For example:

    using UnityEngine;
    using UnityEngine.Video;
    
    public class NearbyVideos : MonoBehaviour
    {
    
        public VideoPlayer videoPlayer;
        public float maxSqrDistance = 100f;
    
        private void Update ()
        {
            float sqrDistance = (transform.position - Camera.main.transform.position).sqrMagnitude;
            videoPlayer.enabled = sqrDistance <= maxSqrDistance;
        }
    
    }
    
  • edited February 2023

    I will try that out.

    The video option looks great in game. A few questions:

    Any chance you'd add a video selection/input box to the Speech Manager Game Text section, along side the audio one? So a looping speech Video could play for the length of a text line. Seems like this would be another good option for animated faces for everyone. Would work for props too if needed.

    Another question, is there a way to wait for an audible line of dialogue is finished before moving to the next action in the Action List without locking up the gameplay?

    Thanks Chris.

  • amendment to question 1: "add game object housing video component in Speech Manager Game Text section"

  • ...and finally, I'm also seeing a small (maybe 0.5 or 1 second) delay after a Dialogue Speech action plays before it moves on to the next action. I've checked the end of the audio file and it is cut right after the last word, so the issue is not there.

    Any idea?

  • add game object housing video component in Speech Manager Game Text section

    A speech line is automatically connected to its associated character upon playing. If you want to add some custom behaviour when a specific line is played, affecting that specific character, you can have a script hook onto the OnSpeechStart custom event. Within this, you can use the line's ID number to play a specific video clip.

    For example:

    using UnityEngine;
    using UnityEngine.Video;
    using AC;
    
    public class VideoSpeechPlayer : MonoBehaviour
    {
    
        [SerializeField] private VideoSpeech[] videoSpeeches = new VideoSpeech[0];
        [SerializeField] private AC.Char character;
        [SerializeField] private VideoPlayer videoPlayer;
    
    
        private void OnEnable () { EventManager.OnStartSpeech += OnStartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech -= OnStartSpeech; }
    
        private void OnStartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            if (speakingCharacter == character && lineID >= 0)
            {
                foreach (VideoSpeech videoSpeech in videoSpeeches)
                {
                    if (videoSpeech.lineID == lineID)
                    {
                        videoPlayer.clip = videoSpeech.clip;
                        videoPlayer.Play ();
                        return;
                    }
                }
            }
        }
    
        [System.Serializable]
        private class VideoSpeech
        {
    
            public int lineID;
            public VideoClip clip;
    
        }
    
    }
    

    is there a way to wait for an audible line of dialogue is finished before moving to the next action in the Action List without locking up the gameplay?

    Set the ActionList's When running property - at the top of its Inspector - to Run In Background.

    I'm also seeing a small (maybe 0.5 or 1 second) delay after a Dialogue Speech action plays before it moves on to the next action

    The default wait time after playing a speech line can be set from the Speech Manager's Initial post-line delay (s) slider.

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.