Forum rules - please read before posting.

Character audio source override

Heyo!

I've got a lot of cutscenes with moving cameras and stuff and in those scenes, speech emitting from the characters just doesn't work for me, since the camera at times is way too far or too close to the character. Is there some way to override the audio source of the character's speech temporarily? I just want non-3d positioned audio for these lines of dialogue.

Comments

  • As a temporary solution I killed the cameras audio listener and put it next to my characters instead.. but in the long run that's a pretty weird solution...

  • You can modify which AudioSource a character uses by re-assigning their speechAudioSource variable.

    However, it's also possible to simply alter the existing AudioSource's spatial blend property, so that an existing AudioSource can play in 2D for a time.

    Here's a custom Action (ActionCharAudio.cs) that should allow you to set this blend amount in an ActionList:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCharAudio : Action
        {
    
            public int charToMoveID = 0;
            public Char charToMove;
            public bool isPlayer;
            protected Char runtimeCharToMove;
            public float blend;
    
            public override ActionCategory Category { get { return ActionCategory.Character; }}
            public override string Title { get { return "Set audio source blend"; }}
    
            public override void AssignValues ()
            {           
                if (isPlayer)
                {
                    runtimeCharToMove = KickStarter.player;
                }
                else
                {
                    runtimeCharToMove = AssignFile <Char> (charToMoveID, charToMove);
                }
            }
    
            public override float Run ()
            {
                if (runtimeCharToMove)
                {
                    runtimeCharToMove.speechAudioSource.spatialBlend = blend;
                }
                return 0f;
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                isPlayer = EditorGUILayout.Toggle ("Affect Player?", isPlayer);
                if (!isPlayer)
                {
                    charToMove = (Char) EditorGUILayout.ObjectField ("Character to turn:", charToMove, typeof(Char), true);
                    charToMoveID = FieldToID <Char> (charToMove, charToMoveID);
                    charToMove = IDToField <Char> (charToMove, charToMoveID, false);
                }
    
                blend = EditorGUILayout.Slider ("2D/3D blend:", blend, 0f, 1f);
            }
    
            #endif
    
        }
    
    }
    
  • Cool, thank you, I'll try this! :smiley:

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.