Forum rules - please read before posting.

System for random Npcs to appear in a 2d visual novel

Hi, I want to make a dialogue system for a 2d game so that when you start the game a different character appears, and when you finish talking to that character, the next one appears, but I have realized that my system would become a loop since one of the 3 characters would be repeated. Could you tell me another system or how to improve the one I have?


  • Welcome to the community, @Ares_s0ul.

    AC has a Variable: Check random number Action that can be used to run different Actions randomly each time it is run, but if you want it to remember previous choices you're better off using a custom script instead.

    If you move each character's dialogue to separate Cutscene (e.g. Talk_CharacterA, Talk_CharacterB) etc, then you can use the script below to run them at random, without running the same list twice:

    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    public class ChooseRandomActionList : MonoBehaviour
        public List<ActionList> randomList;
        public ActionList exhaustedList;
        private System.Random rng = new System.Random();  
        private void Start ()
            Shuffle (randomList);
        public void Interact ()
            if (randomList.Count > 0)
                ActionList actionList = randomList[0];
                randomList.RemoveAt (0);
                actionList.Interact ();
            if (exhaustedList) exhaustedList.Interact ();
        private void Shuffle<T>(IList<T> list)  
            int n = list.Count;  
            while (n > 1) {  
                int k = rng.Next(n + 1);  
                T value = list[k];  
                list[k] = list[n];  
                list[n] = value;  

    To use it, paste the code into a C# file named ChooseRandomActionList.cs, and attach to a new empty GameObject in your scene.

    In its Inspector, assign each of the character dialogue Cutscenes into the "Random List" array. Optionally, you can assign a Cutcene into the "Exhausted List" field, which will run once all other lists have been run.

    Then, whenever you want to have this script run a Cutscene at random, use the Object: Send message Action on its GameObject, setting the Message to send field to Interact.

  • Thanks for the response. The idea is that 3 or 4 random characters can appear in the same scene and when all these characters appear it happens the next day, that would be in a new scene and with the same or other characters with different conversations and they remember the options that you have decided in scene 1, etc. With what you have explained about making different scenes for each character, can you also make a scene with all the random characters in this way?

  • My post above doesn't involve separate scenes, but separate Cutscenes (or ActionList). Each NPC is present in the same scene, but their dialogue is placed in a separate list.

  • I have tried it and it is just what I wanted but there is a problem. It lets me move the cursor but it doesn't let me interact between the dialogue options or other objects in the scene, when I remove the option to interact as you explained to me before, it works. any way to fix it?

  • The Interact function runs an ActionList you assign in its Inspector - if it blocks gameplay, it'll prevent interactions. Don't be confused by the similar names - you could rename "Interact" to "RunActionList" to make it more clear.

    Only run this function once you want an NPC to being talking - how are you currently using it? Any screenshots of your setup that you can share will help clarify the exact situation.

  • I have set that when the dialogues begin, the games continue to work from behind and let me open the book that appears in the recording, but when the options to choose an answer appear, the cursor does not appear changed as at the beginning of the video and it does not let me select moving the cursor.
    Basically in the dialogues the cursor works and interacts with the book and when I have to choose an answer it doesn't let me interact with anything and if there are several answers it doesn't let me choose them with the cursor.
    Don't mind the scene is a placeholder hahahaha.

  • Everything is already fixed. I had the boxes that start with "directly" checked, I unchecked them and everything has been resolved, the cursor already works in the scenes to choose.
    Many thanks for everything.

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.