Sign in to follow this  
getinthedamnbox

Conversation System in Unity

Recommended Posts

I'm working on a solo project in Unity (C#), and I need to script something that will handle conversation between characters. Players won't be able to choose between dialogue options, and there's no UI, so basically all I need is to be able to manage a large number of sound assets in an organized way. Before diving in, I thought I'd ask if anyone here could offer any ideas.

 

Previously, I had started managing conversation with a list of sound assets and a function that could be called to play one of them. So, there was a lot of "if (Time.time >= nextLine)" to determine when the next line of conversation should be played, etc. My Game Controller script was riddled with calls for lines of conversation... it was gross and confusing.

 

Ideally, I want something that will store properties about each line of conversation (e.g., who is the speaker, what is said in the line, how long is the line, should the line be interruptible, should the line be repeatable, has the line already been said, what triggers the line), so that I can avoid having "SayDialogue (12);"s everywhere, and so that I can revise the sound assets and their properties in one location. Also, I'm thinking it might make sense to have a conversation queue, so that lines that are ready to be played stack up in there instead of interrupting each other.

 

I don't have a formal CS background, so my main problem is that I don't know what my options are with designing this. I was thinking of trying to use an array to store the assets/properties and a list for the queue... Is there something else that I should also explore? Or am I overthinking this?

 

Any tips or advice would be greatly appreciated. For reference, you can read my devdiary and/or play my latest build here.

 

Thanks!

Share this post


Link to post
Share on other sites

It sounds like you should create a new class for lines that includes the properties you need including a reference to the audio-asset that will be stored in an array.

Then you could have an array of those lines (now a bunch of instances of a class) that could be called based on checking the array of lines for a particular value or just going through the array in order.

Share this post


Link to post
Share on other sites

The simplest thing would be to pick a conversation system from a game you like and just try to make a copy of it. That should give you an idea of what needs to be done. Whatever you decide you'll likely need

- a conversation section class that contains the line, audio file, speaker, localized text, etc

- a way of transitioning between conversation sections via input or however you like

- some way of displaying the information via a menu panel, which can be used to start and end conversations

Attached are some images of a basic conversation system I wrote, which just cycles through conversation sections from the start to the end of the array. The first image is the inspector and what the classes look like, and the second is the in game result.

post-28069-0-94398400-1442698358_thumb.png

post-28069-0-30026400-1442698363_thumb.png

Share this post


Link to post
Share on other sites

Very cool, clyde and itsamoose---this is exactly the kind of help I needed. Thank you. I have a much better idea of how this should work now, and I'm going to give it a shot.

 

I like the art style of your game, itsamoose! Baba Yaga always makes me nostalgic for Quest for Glory... :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this