How to remove an inky story that has been added to the database at runtime?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
sawiyon
Posts: 5
Joined: Sun Feb 13, 2022 9:58 am

How to remove an inky story that has been added to the database at runtime?

Post by sawiyon »

Heya, I have a quick question!

I can add inky stories at runtime, but I haven't yet figured out how to remove them from the database afterward. I ask this question because I need to be able to reset the database or delete/remove a story when necessary (at runtime).

Thanks in advance. :)
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to remove an inky story that has been added to the database at runtime?

Post by Tony Li »

Hi,

No need to remove the story. To reset the data, call the DialogueSystemInkIntegration component's ResetStories() method. Example:

Code: Select all

DialogueManager.instance.GetComponent<DialogueSystemInkIntegration>().ResetStories();
sawiyon
Posts: 5
Joined: Sun Feb 13, 2022 9:58 am

Re: How to remove an inky story that has been added to the database at runtime?

Post by sawiyon »

Hey, thank you for the quick answer! I'm sorry for the misunderstanding. I need to remove the story from the database.
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to remove an inky story that has been added to the database at runtime?

Post by Tony Li »

Hi,

In that case, I recommend making a subclass of DialogueSystemInkIntegration and adding a method to remove it. Example:

Code: Select all

using Ink.Runtime;
using PixelCrushers.DialogueSystem;
using PixelCrushers.DialogueSystem.InkSupport;

public class DialogueSystemIntegrationSubclass : DialogueSystemInkIntegration
{
    public void RemoveStory(string storyTitle)
    {
        var conversation = database.conversations.Find(x => x.Title == storyTitle);
        if (conversation == null) return; // No such story.
        Story story;
        if (!storyDict.TryGetValue(conversation.id, out story)) return; // Story not in dict.

        // Remove database from DS, remove story from database, then re-add database to DS:
        DialogueManager.RemoveDatabase(database);
        storyDict.Remove(conversation.id);
        stories.Remove(story);
        DialogueManager.AddDatabase(database);
    }
}
sawiyon
Posts: 5
Joined: Sun Feb 13, 2022 9:58 am

Re: How to remove an inky story that has been added to the database at runtime?

Post by sawiyon »

Thanks, this helped me to get on the right track!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to remove an inky story that has been added to the database at runtime?

Post by Tony Li »

Glad to help!
Post Reply