Forum rules - please read before posting.

Script to wipe stuck subtitles

Hi Chris, would the below script allow me to wipe subtitles that were stuck? This usually happens when an NPC is speaking an dthen the scene changes whilst they may not have finished their speech and it gets stuck on for the rest of the game. I wanted to incorporate a fail safe on scene change

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;

public class SubtitleManager : MonoBehaviour
{
    // Reference to Adventure Creator's Subtitle system
    private Subtitles subtitles;

    void Start()
    {
        // Get the Subtitles component from the Adventure Creator system
        subtitles = GameObject.FindObjectOfType<Subtitles>();
    }

    // Method to display subtitles
    public void DisplaySubtitle(string text, float duration)
    {
        if (subtitles != null)
        {
            // Display the subtitle with the given text and duration
            subtitles.HandleText(text, duration);
        }
        else
        {
            Debug.LogWarning("Subtitles component not found!");
        }
    }

    // Method to remove subtitles
    public void RemoveSubtitle()
    {
        if (subtitles != null)
        {
            // Remove any currently displayed subtitles
            subtitles.Hide();
        }
    }

    // Method to refresh subtitles (to prevent overlapping)
    public void RefreshSubtitle(string text, float duration)
    {
        RemoveSubtitle(); // Remove any existing subtitles
        DisplaySubtitle(text, duration); // Display new subtitle
    }

    // Example usage:

    // To display a subtitle
    public void ExampleDisplay()
    {
        DisplaySubtitle("Hello, world!", 3f); // Display "Hello, world!" for 3 seconds
    }

    // To remove a subtitle
    public void ExampleRemove()
    {
        RemoveSubtitle(); // Remove currently displayed subtitle
    }

    // To refresh subtitles
    public void ExampleRefresh()
    {
        RefreshSubtitle("New subtitle", 2f); // Remove current subtitle and display "New subtitle" for 2 seconds
    }
}

Comments

  • Not at all - Subtitles it not an AC class, and has no functions that match the names of those called by the script.

  • Thanks Chris, any tips on where to start with this one?

  • The issue with ChatGPT is that it just makes stuff up. It's almost ridiculous how annoyed I was reading that code lol - I'm not saying I was annoyed with you, jamesfootlight, just at how the LLM "confidently" bluffs through a solution like a student who didn't do their homework and is now trying to pretend they know everything. It sounds like a kid writing a lit paper about a novel they didn't read.

    Anyway, you don't need code for this. Just use the Events Editor to create an event that turns off your subtitle menu on scene changes.

  • Thanks, yes, you are correct, and I did try and teach it to help me and guide me, as a starting point. Feeding it the correct info etc. But anyhow, you are correct. PS with some pointers and explanation through tutorials I have managed to get some good scripts and custom action lists working. Through extreme patience and iterations. Only ever started last week seeing what Chat GPT was.

    PS my issue is that I don't even think it is the subtitles that need turning off, it is almost like a printed hangover on screen, the subtitles continue to play, but it rare instances teh echo, in white text, stay on screen for the rest of the game, and TBH I've asked help a while back for a solution or advice, without remedy. So tried to sort myself (Yes with our evil AI overlords) - But I still have the issue and wondered just how I could eradicate the text hangover on screen. As I say rare, but annoying when it happens.

  • edited April 5

    Ah that's weird - I've never seen an artefact like this. Have you been able to reproduce it/make a video of it? I'm having a hard time picturing it properly. Is the menu source AC or Unity UI?

  • edited April 5

    You raised this issue six years ago here, but I need answers to my questions in order to uncover the cause.

    The thread is too old to be valid any longer. If it is still occuring in the latest release, create a new thread with full details.

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.