Multiple Npc Talking

Home Forums Books Mastering Unity 2D Game Development Multiple Npc Talking

This topic contains 12 replies, has 2 voices, and was last updated by  Simon (darkside) Jackson 2 years, 11 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #8379

    Willam Naaden

    Hi I just finished Ch 5 and my conversation is working perfectly but when I try to add another conversation it always overwrites my first one and I end up with all the Npcs saying the same thing. Thanks.

    #8380

    Ok, just so I understand correctly.

    You have the player and the Wizard talking fine.  But when you add a new conversation between the player and someone else it isn’t working.

    Could you detail a little what your trying to do please.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #8389

    Willam Naaden

    Sorry for being so vague. What I mean is when my player collides with the left boarder, Graybeard starts his conversation perfectly. I made another conversation for Olaf such as “These monster attacks are getting out of hand.” When I collide with him he says that. But the problem is that when I collide with Graybeard again he says the same thing Olaf does. I hope you understand me. Thanks.

    #8394

    Oh no worries.

    I tested this locally and I think what is tripping you up is the event subscription.  If you are using the same event subscriber for both characters (basically you are shouting to everyone) only the first conversation will start.

    Ideally, you need to set up a new event channel for the second character (new subscription list in the Messaging manager and supporting functions) and Broadcast // receiver scripts for the new character.

    While this may seem a bit bulky, it still means you have a robust system that is reusable and doesn’t collider with any other kind of messaging and does not require hard coding.

    Granted, it would be improved (in fact I added an option in my local script to update the “completed” status of a conversation when it had finished, so that you wouldn’t see it twice)

    With the new UI system, it brings a new style of event system which is a lot more flexible, so if you saw my announcement about a set of articles to update the GUI system to the new UI system, it will cover that as well.  As ever buying the UI book isn’t mandatory and I’ll ensure you get all the info you need in the extended tutorial (although preferred obviously :D, as there is a lot of information about the UI system in the new book)

     

    Hope this helps.

     

    P.S.

    If you want me to share the script updates I did for subsequent character conversations, let me know and I’ll post them.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #8395

    Willam Naaden

    Thank you sooooo much.

     

    P.S.

    Just to make sure my coding is correct please post the script. Thanks again!

    #8420

    Willam Naaden

    Sorry to bother you again 😐 I understand what you’re saying but I’m having a lot of trouble converting your logic into code(I’m really knew to c#). This problem is really putting a hole in my project so could you please post some scripting.

    #8421

    Willam Naaden

    Sorry to bother you again:( I understand what you’re saying but I’m having a lot of trouble putting your logic into code(I’m really knew to c#). This problem is putting a big hole in my project so if you could please post the code I need that would be great. Thanks.

    #8424

    Hi Will, thanks for your patience.  I’m back from holiday now, so will post up my code changes the moment I can (slight mountain of mails and work to climb through)

     

    Will sort it as soon as I’m able.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #8475

    OK, finally got round to posting the example code (apologies it took so long)

    Updated Messaging manager, adding a new event subscriber for the new conversation.  (Granted this is bulky at present, will do a new version with the new UI eventsystem)

    http://pastebin.com/2UkZuqfj

    New Broadcast receiver for the new conversation, for adding to the new character.  Don’t forget to also add a ConversationComponent and a new conversation asset!

    (Granted, this could be refactored to be more generic given the only difference is the list is subscribed to)

    http://pastebin.com/Jwx9VHmX

    Finally, the Broadcast script to alert when the conversation should start, should be attached to the collider trigger to begin the conversation.

    http://pastebin.com/Cf86bDjd

    As a bonus, I also updated the conversation manager script to set the completed flag on the conversation so it only plays once.

    http://pastebin.com/sdnpMLMe

     

    At present it only plays one conversation at a time and if a conversation is in progress, new conversations won’t start until the previous is done.  One of the stretch challenges I set was to also have an event to stop an active conversation if the player got too far away 😀

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #8477

    Willam Naaden

    Am I missing some code because I have two errors:

    Assets/Scripts/ConversationManager.cs(51,30): error CS1061: Type Conversation' does not contain a definition forComplete’ and no extension method Complete' of typeConversation’ could be found (are you missing a using directive or an assembly reference?)

    and

    Assets/Scripts/Messaging/MessagingManager.cs(11,29): error CS0246: The type or namespace name `InventoryItem’ could not be found. Are you missing a using directive or an assembly reference?

    #8478

    Ok the inventory item error is probably because you haven’t gotten to the inventory chapter yet. just strip out that subscriber and methods for now if you wish.

    As for the Complete error, there should be a property on a conversation item called “Complete” (should be one there already, so not sure why you haven’t got it). Check the download source for Ch 11/12 if your not sure.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #8479

    Willam Naaden

    Well worth any wait!!!!!!!!! Got rid of the inventory item stuff and it works like a dream!!!!!!!!! Thank you a billion!!!!!!!!!!!

    #8480

    No worries, happy to help.

    When I get to update the conversation screens to the new UI, I’l be sure to keep this scenario in mind and include it.

    Simon (Darkside) Jackson
    @SimonDarksideJ

Viewing 13 posts - 1 through 13 (of 13 total)

The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.