Forum rules - please read before posting.

Prefab for Conversations and Actionlists

edited December 2020 in Technical Q&A

In my game, I want my NPCs to be at random locations, or even in different scenes. Each time the PC enters that area, it randomize the location. The PC can talk to those NPCs and should have conversations with them
I can easily spawn prefabs of the NPC, but it seems I can't save as a prefab a Actionlist, or a Conversation asset.

How can I create a conversation (using Actionlist and Conversations asset) that could happen in different scenes?

Comments

  • When dealing with prefabs, you'll want to rely on ActionList assets. Each of AC's logic objects (Conversations, Hotspots, Triggers, etc) can be made to work with ActionList assets instead of scene-based ones. Just set its Interaction source field to Asset File and you'll be able to have assets run when options are chosen instead.

    A tutorial on working with prefab logic can be found here.

    Conversations in particular are a little tricky, because presumably you want to turn dialogue options on/off based on other logic or options, as well as record such changes in save game files.

    The way to handle this is to make your Conversations "global", by attaching a script to keep them in the scene at all times. For example:

    using UnityEngine;
    
    public class DontDestroyMe : MonoBehaviour
    {
    
        private void Start ()
        {
            DontDestroyOnLoad (gameObject);
        }
    
    }
    

    Place that in a C# file named DontDestroyMe, attach it to your Conversation, and make it a prefab. Then attach a Constant ID component, and check Retain in prefab? - you should find that the prefab then has a Constant ID value displayed in the Inspector.

    Next, drop the prefab into your game's first scene. When you switch scene, the Conversation prefab will remain in the scene (or specifically, the "DontDestroyOnLoad" sub-scene in the Hierarchy).

    This Conversation can now be accessed from anywhere. Just be sure to have your Dialogue: Start conversation Action reference the Conversation prefab. When the Action is run, it'll look for the Conversation object in the scene by comparing the recorded Constant ID value.

  • Thanks Chris, that should work.

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.