Forum rules - please read before posting.

When narrator speaks have camera effect from sc post effect asset

Hi,

I appreciate the SC Post Effect asset is not related here, but how would I hook into the speech of a specific character? Basically I would like an SC Post Effect to happen when a specific NPC character speaks. Are you able to offer some code / assistance as to how to do this? Thanks!

Comments

  • You can hook into the OnStartSpeech / OnStopSpeech custom events to get callbacks when a specific character starts and stop speaking:

    using UnityEngine;
    using AC;
    
    public class SpeechEventsExample : MonoBehaviour
    {
    
        public Texture2D speechIcon;
        public Texture2D defaultWaitIcon;
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech += StartSpeech;
            EventManager.OnStopSpeech += StopSpeech;
        }
    
        private void OnDisable ()
        {
            EventManager.OnStopSpeech -= StopSpeech;
            EventManager.OnStartSpeech -= StartSpeech;
        }
    
        private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            // Character 'speakingCharacter' startedSpeaking
        }
    
        private void StopSpeech (AC.Char speakingCharacter)
        {
            // Character 'speakingCharacter' stopped speaking
        }
    
    }
    

    speakingCharacter will be 'null' in the case of narration.

  • Morning Chris,

    Can you check the below, it is not quite working, I drag the player in from the scene, but the effect does not happen when my NPC speaks. It is normal npc dialogue. see screenshot here

    using UnityEngine;
    using AC;
    
    public class SpeechEventsExample : MonoBehaviour
    {
        public AC.Char targetCharacter;
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech += StartSpeech;
            EventManager.OnStopSpeech += StopSpeech;
        }
    
        private void OnDisable ()
        {
            EventManager.OnStopSpeech -= StopSpeech;
            EventManager.OnStartSpeech -= StartSpeech;
        }
    
        private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            if( speakingCharacter != targetCharacter ){
                return;
            }
            ModifyEffect.ModifyEffectStart();
            // Character 'speakingCharacter' startedSpeaking
        }
    
        private void StopSpeech (AC.Char speakingCharacter)
        {
            if( speakingCharacter != targetCharacter ){
                return;
            }
            ModifyEffect.ModifyEffectEnd();
    
            // Character 'speakingCharacter' stopped speaking
        }
    
    }
    
  • Use Debug.Log statements underneath the ModifyEffect calls to confirm that they are being called at the correct time.

    If they are, the script is working and it's not AC-related.

    If they aren't, re-word your description of what exactly is happening. The screenshot shows an effect kicking in - what's the exact issue?

  • So the effect isn't happening when the npc speaks, the effect is there if I turn off the ModifyEffect script, but when it turns on it is waiting for the npc to speak and then turn on, but it isn't turning on

  • so we ran a de bug and there was no mention in the console, which would suggest that the OnStartSpeech is not getting called. So, the ModifyEffect is attached to the SC Effects and in runtime, the effect is not happening (it is visible in scene window not in play mode) and then when Narrator speaks I want the effect to be visible, and then when the narrator stops speaking, the effect stops

  • edited January 2023

    Scrap that, my bad, it is working, but not having any effect in game, anything you can see from this error that needs doing to the script? Here is the console message:

    ModifyEffectStart:Narrator (AC.NPC)
    UnityEngine.Debug:Log (object)
    SpeechEventsExample:StartSpeech (AC.Char,string,int) (at Assets/Sleepytime Village/Scripts/SpeechEventsExample.cs:30)
    AC.EventManager:Call_OnStartSpeech (AC.Speech,AC.Char,string,int) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:92)
    AC.Speech:.ctor (AC.Char,string,int,bool,bool,bool,UnityEngine.AudioClip,UnityEngine.TextAsset) (at Assets/AdventureCreator/Scripts/Speech/Speech.cs:177)
    AC.Dialog:StartDialog (AC.Char,string,bool,int,bool,bool,UnityEngine.AudioClip,UnityEngine.TextAsset) (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:161)
    AC.ActionSpeech:StartSpeech (UnityEngine.AudioClip,UnityEngine.TextAsset) (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:908)
    AC.ActionSpeech:Run () (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:192)
    AC.ActionList/<RunAction>d__45:MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:460)
    UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
    AC.ActionList:ProcessAction (int) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:410)
    AC.ActionList:ProcessActionEnd (AC.ActionEnd,int,bool) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:609)
    AC.ActionList:EndAction (AC.Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:568)
    AC.ActionList/<RunAction>d__45:MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:532)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Coroutines.cs:17)
    
  • edited January 2023

    The log - not an error - shows that the ModifyEffectStart is being called with the correct NPC assigned. That the effect is not working is down to the ModifyEffect side of things.

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.