Forum rules - please read before posting.

Bet approach for handling 50+ characters in one scene?

Hi!

I wanted to have multiple characters in one scene (50+), and I'm trying to come up with the best approach to handle all the data. The characters don't appear all at once, instead, imagine running a shop- it's more like having a few clients a day in the scene, but I need a way to store all of the clients and their data.

Currently I have a separate scene, and in that scene I plan to store all the character objects, later turning them into prefabs. In the main game scene (the shop) I use Instantiate(); to make a clone of the character so you can talk to him. The Character says couple of lines, and later player has a dialogue option to choose from (I believe Conversation is basically a set of dialogue options?). From what I can see, the Conversation also needs to be Instantiated, which becomes problematic when dialogue needs to be fairly complex. I was planning on having dialogues where player constantly has new options to chose from. Originally I wanted to use multiple Conversation assets for each of the newly unlocked dialogue options, but that will be a nightmare to keep having to Instantiate them over and over again.

Example dialogue:
(C)lient: Good morning!
--- Conversation 1---
(P)layer: Hi.
(P): How are you?
(P): How can I help

Each option has it's response, ultimately leading to the next Conversation

(C): I want this fancy plush cat.
--- Conversation 2---
(P): Sure.
(P): Anything else?
(P): Let me get it for you.

One dialogue could be made of multiple dialogue options like this...

When dialogue options from Conversation 1 are visible, you don't get to see the Conversation 2, and vice versa. From what I understand, I could have one Conversation, and simply enable/disable required dialogue options, but it seems that the ActionList will get cluttered quite fast with Dialogue:Toggle Option. Instead, I was hoping to use multiple Conversations through Dialogue:Start Conversation, which would make the ActionList a lot easier to read. The problem with this, is that I would have to Instantiate each of the Conversation Asset - seems like I can't just drag a Conversation prefab into Dialogue:Start Conversation as Unity complains with "CharacterConv2" is inactive!.

Is there something I'm missing? Would there be a better and easier way of handling this type of thing?

Comments

  • I would start off by making prefabs - Unity 2018.3 finally brings the ability to create nested prefabs and prefab variants, which is ideal for creating many NPCs with slight differences between them.

    Parameters and variables are also recommended to simplify / reduce the amount of ActionLists etc you need to create. A generic "Talk to NPC" ActionList could handle things like the Player facing and greeting the NPC, for example, with parameters to make the NPC dynamic and variables read to make variation where necessary.

    Parameters and variables can both be set dynamically at the time an ActionList runs by hooking into the OnBeginActionList custom event.

    The Conversation object itself needs to be in the scene - it shouldn't be spawned in at runtime. There are steps you can take to make a Conversation "global", however - see this wiki page.

    Keep your Conversation(s) in your scene, but the ActionList(s) that control them can be asset files. The Dialogue: Start conversation Action supports the ConstantID system, so you can make changes to a Conversation's options, or run a different Conversation after choosing a particular option, from an asset.

    Tutorials on the Conversation system can be found here.

  • Thank you for the reply, I think I can create a nice workflow to make use of prefabs, parameters, variables etc.

    I'm a bit worried that if the Conversation objects need to be in the same room, it will make the scene very heavy on the performance.

    If there's ~50 characters, all prefabs, so they will come and go, but let's say that each dialogue has 3 Conversations, then that's at least 150 Conversation objects in one scene. Would that be a problem? I have no idea how performance heavy one Conversation could be.

    Other than that, I think I will be able to work something out. The global Conversations will probably be very useful, so thanks for the tip!

  • After setting up some more prefabs, I ran into a problem.

    All prefab characters instantiated at runtime can't be moved through Character:MoveToPoint - not from the native Action, or not if done through custom Action. The PlaySpeech Actions work with them, but the dialogue GUI is often misplaced and not above the character.

    If the character is placed in the scene from the start, I can move him, but the dialogue GUI still seems to be off.

    Constant ID number is assigned and Retain in prefab? is selected.

    Unity: 2018.2.18f1
    AC v1.65.2

  • To be clear: a Conversation can still be spawned into the scene at runtime, I just meant that you can't run a Conversation directly from it's asset file. It will need to be in the scene, however, for saving to work.

    With the instantiated characters, are you using multiple instances of the same prefab - or just dealing with one instance per prefab? There shouldn't be an issue with controlling a spawned character like this. Are your Actions in ActionList assets, or the scene - and are you seeing "Recorded Constant ID" values underneath the fields?

    Let's see some screenshots to understand what's going on.

  • Just to make sure: Conversation needs to be in the scene for the save to work, but the Conversation object can be instantiated at the moment of saving?

    I'm dealing with one instance per prefab.

    ActionList is in the scene - I'm loading the scene and I run OnStart ActionList. The custom Action that's run is essentially this:

            Quaternion rotation = new Quaternion();
            Instantiate(petitioner, queueOffScreen, rotation); // spawns off screen
    
            Char myChar = petitioner.GetComponent<Char>();
    
            myChar.MoveToPoint(marker,false,false);
    

    I spawn the character off screen and later move him to the marker. The NavMesh extends off screen as well, but even if the character is spawn in the scene (and on NavMesh) he still won't move to the position.

    I just tested with having the above custom Action followed with native Character:MoveToPoint Action and the character moves just fine. I suspect the problem is with instantiating the character and moving him straight after.

    Screenshots:
    Character has Constant ID in custom Action

    Debug says no Path script and no default NavMesh

    But the Instantiated character has Paths Script

    Again, Constant ID is attached to the character

    And default NavMesh is set

  • Your specific issue with the code isn't related to AC - you're still referring to the prefab, not the spawned character. You'd want something like:

    GameObject spawnedObject = Instantiate(petitioner, queueOffScreen, rotation); // spawns off screen
    Char myChar = spawnedObject.GetComponent<Char>();
    

    Also know that the Object: Add or remove Action provides a built-in way of spawning objects - that's what I'd assumed you were referring to.

    Conversation needs to be in the scene for the save to work, but the Conversation object can be instantiated at the moment of saving?

    No, because the data you want to save would then be reset. You can, however, write a custom Remember script to store the data of all your Conversations in one go. It would be a bit tricky - you'd have to make sure the Conversation gets such saved data loaded in after spawn but before running - but it would be possible.

    A Conversation itself is very lightweight, however - I don't think you should worry about performance impact unless you actually experience anything amiss.

  • Sorry, I'm pretty new to Unity as well as AC. It didn't even occur to me that I would still be referring to the prefab at this stage. Having read other threads on the forum I've thought it must have been something wrong with the way I've set up the prefab etc.

    All makes sense now and it's fixed though.
    Thank you for the support and the tips! I will look into custom Remember script!

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.