Forum rules - please read before posting.

Speed Lines to appear when subtitles off too

I have a script which hooks into my Global Post-process Volume and when the Narrator speaks the effect comes on, however it doesn't come on when subtitles are turned off. Any idea how to change this script so that it happens when the chosen character is speaking regardless of subtitles on?

This is the script:

using UnityEngine;
using UnityEngine.Rendering;
using AC;

[RequireComponent(typeof(Volume))]
public class SpeakerSpeedLines : MonoBehaviour
{
    public Volume volume;
    public Char speaker;
    public float blendInSpeed = 4f;

    public AnimationCurve intensityCurve = new AnimationCurve(new Keyframe[]
  {
        new Keyframe(0f, 0f), new Keyframe(0.5f, 1f), new Keyframe(1f, 1f)
  });

    private SCPE.SpeedLines _speedLines;
    private float _progress;
    private bool _speaking;

    void SpeechStarted(Speech speech)
    {
        if (speaker != speech.GetSpeakingCharacter())
        {
            return;
        }

        _speedLines.active = true;
        _speaking = true;
        _progress = 0.0f;
    }

    void SpeechStopped(Speech speech)
    {
        if (speaker != speech.GetSpeakingCharacter())
        {
            return;
        }
        _speedLines.intensity.overrideState = false;
        _speedLines.intensity.value = 0f;
        _speaking = false;
        _progress = 0.0f;
    }

    private void OnEnable()
    {
        EventManager.OnStartSpeech_Alt += SpeechStarted;
        EventManager.OnStopSpeech_Alt += SpeechStopped;
    }

    private void OnDisable()
    {
        EventManager.OnStartSpeech_Alt -= SpeechStarted;
        EventManager.OnStopSpeech_Alt -= SpeechStopped;
    }

    private void Reset()
    {
        volume = GetComponent<Volume>();
    }

    private void Start()
    {
        volume.profile.TryGet(typeof(SCPE.SpeedLines), out _speedLines);
        _speedLines.intensity.overrideState = true;
        _speedLines.intensity.value = 0f;
    }

    void Update()
    {
        if( !_speaking || !_speedLines )
        {
            return;
        }

        _progress += (blendInSpeed * Time.fixedDeltaTime);

        //An kind of parameter that controls the visibility of an effect (eg. intensity) is always between 0 and 1
        _progress = Mathf.Clamp01(_progress);

        //Depending on the effect, the "main" parameter may be called different. Most of the time the parameter is called "intensity".
        //You can use IntelliSense to browse the available parameters (CTRL+Space after the period).
        //The .value path points to the actual value of the parameter (it may be a float, color, int, etc...)
        _speedLines.intensity.overrideState = true;
        _speedLines.intensity.value = intensityCurve.Evaluate(_progress);

        //Debug.Log($"Intensity:{_progress}");
    }
}

See screenshots here please:

https://drive.google.com/drive/folders/19uuop8UiM3vlyzGKXZwcQHZNAkxeju2-?usp=share_link

Comments

  • The lack of Subtitles won't prevent the events from firing.

    Place Debug.Log statements inside the event functions to confirm this - they should show regardless.

  • Ok I will check, I realise this is not playing in the build but it is playing in Unity

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.