Search Unity

NPC Chat

Discussion in 'Assets and Asset Store' started by Stephen_O, Mar 1, 2014.

  1. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    NPC Chat is 30% off for the Mega Sale!
     
  2. GamePowerNetwork

    GamePowerNetwork

    Joined:
    Sep 23, 2012
    Posts:
    257
    hI @TurnTheGameOn is there an easy way to support localization with this asset? Right now it seems you can only enter english.

    Thanks for the great asset by the way.
     
    Stephen_O likes this.
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hi PyroStudios,

    Yes, you're right there's no built in localization option right now.

    I'm in the middle of an update for my racing project right now, but plan to give NPC Chat some update love when finished there. I think this would be a very useful feature to add and probably something this asset should have, I'll make sure to add it when I get around to the update (I don't know how long it will take until I can start on this).

    For now the best way to approach localization would be to try to create a script that can load text data into the NPC Chat text arrays at run-time from a source of your choosing after it determines the correct language source to use.

    This would be a custom integration that you would need to code and might be a little advanced..

    NPC Chat is basically a data container with a fancy UI to help assign settings, you would basically build your dialogue in the documented way, then flip over to debug mode to view the array indexes from the inspector pictured below to see how it's setup. There are 3 text fields in each array index that would need to be populated (Chat page, NPC name and button string).

    NPC Chat Dialogue Arrays.jpg

    Your custom script would need to have dialogue indexes for each instance of NPC Chat in your game, each of those indexes would contain indexes for the specific NPCs dialogue; in a sense you'll be creating an alternate master copy of all NPC Chat text in a separate data container and have your localization manager pass the text to NPC Chat arrays at scene startup or sometime before the NPC is interacted with. It probably would be best to build this as a scriptable object so you can just duplicate when finished with one language and repopulate with new localization text.
     
    GamePowerNetwork likes this.
  4. pretorpf

    pretorpf

    Joined:
    Sep 30, 2016
    Posts:
    2
    Great asset thank you. I sometimes have problems with the text (showing random letters) and the buttons not appearing. If I restart the game the text will be correct and buttons will be there. I am using Unity 2017. Any help will be appreciated. Thanks
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Has this happened to you in one of the demo scenes? Can you give me the steps you've taken so I can try to reproduce the bug? I've tested in Unity 2017 and 2018 beta and did not notice any problems.
     
  6. pretorpf

    pretorpf

    Joined:
    Sep 30, 2016
    Posts:
    2
    Hi,
    This is not from the demo scenes, I haven't tested that. I followed your video tutorial and created a chat for one of my npc's. This does not happen running the game from the editor, it is after the game is compiled/build and only happens on the first run. I will try to do another test using your demo scene as well to see if I get the same problem, was just hoping it was a known issue or caused by something I am doing wrong. For the buttons I have noticed that if I do not use "Scroll Page Text" no buttons are displayed as soon I turn it on the buttons will appear.
     
    Stephen_O likes this.
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    It sounds like there might be a setting that's not right, maybe it's the conversation index for that NPC on the Chat Manager causing the NPC to produce unexpected results..

    It's best to make sure every NPC starts at conversation 0, unless you want to create an advanced system on top of the chat manager that manages and controls conversation indexes for you.

    There's also an option to make sure buttons are enabled at the start of a page - in case you're not scrolling text or for any other reason. You can disable the Enable After Dialogue option in the Page Buttons category to have buttons auto enabled.
     

    Attached Files:

  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hello,

    I apologize for late response and the errors, this is a bug in the way I configured and setup the NPCs from the last update I made.

    I have a fix ready and will be submitting the update tonight - if you need it before it becomes available on the store please email me.
     
  9. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.8.5 submitted.

    • Fix configuration errors in the NPC Chat Examples scenes.
    • Fix a bug where key up's on NPCs using keyboard input would trigger the FinishPage method while not talking, resulting in an empty dialogue box appearing while out of range.
    • NPCChat.cs some light script optimizations and cleanup - more will come in next updates.

    This version is primarily a bug fix. I'm going to begin working on another update primarily focused on asset/component optimizations... this process will likely result in new tutorials and an update to the inspectors/workflow. If anyone currently using the asset would like to bring up any feature requests I can consider making a change for those too.
     
  10. bassmaMH

    bassmaMH

    Joined:
    May 20, 2018
    Posts:
    5
    Hello. I’m in a bit of a fix here. There is an error concerning first selection option: null reference exception, object reference is not set to an instance of an object.

    What do I do ?
     
  11. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hi,

    It sounds like you like don't have a reference set for a conversation on your NPC.

    I'm not able to determine what configuration steps you've made to setup your NPC, can you please provide some more info and also include the full error that appears in the console window?
     
  12. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.8.6 submitted.

    • Added NPC Chat inspector foldouts for better inspector orginization and readability.
    • NPCChat.cs script optimizations and cleanup
    • Added direct references to the chatbox component to remove getcomponent calls from chat logic.

    Note: The inspector layout changed a little, if something in the tutorials is not visible it's been moved under a foldout category - just expand the category name and you'll find the relevant options. I've added a screenshot below highlighting the new categories in the inspector.
     

    Attached Files:

  13. bassmaMH

    bassmaMH

    Joined:
    May 20, 2018
    Posts:
    5

    Thank you for the quick reply.
    That was the full error that I wrote. (At assets/turnthegameon/npc chat/scripts/chatbox.cs:158 )
    When I set the selection option to none it produces a different error saying: please choose your selection option. So my question is : what is a selection option and how can I properly configure my NPC ? Thank you.
     
    Last edited: Jun 2, 2018
  14. bassmaMH

    bassmaMH

    Joined:
    May 20, 2018
    Posts:
    5
    There is a bigger problem now. The webgl build crashes when I press enter to chat with the npc.
     
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I'm still not sure what's improperly configured since I don't know what steps you've taken to setup your NPC, although it sounds like it could be related to the Event System. It's most likely the NPC Chat • Event System UI Navigation tutorial linked below that will help you find the missing reference.

    There's a scene named NPC Chat Examples with 10 different configuration types. I've attached a screen shot below, if you're not sure what might not be properly configured you can compare your NPC to one of these.

    The demo scene NPC named Structured Dialogue Example Arrow Keys can be referenced as an example for configuring an NPC that uses keyboard input - it sounds like that's how you're trying to configure your NPC.

    Selection is the current UI button that's selected by the scene's Event System - this is a built in Unity component. If you don't have an Event System you'll need to add one to your scene, you can reference my default config on the Event System used in the demo scene noted above. I've added a screen shot for the chat box used for arrow key navigation, in the demo scene I only added Button 0 as the first selection.

    You can also follow the tutorial videos linked below to learn more about how the the dialogue system.
    NPC Chat Introduction Tutorial:
    NPC Chat Seamless, Structured & Dynamic Dialogue:
    NPC Chat • Event System UI Navigation: [

    Having a run time error will cause a webgl app to crash, it's crashing because of the null reference exception, object reference is not set to an instance of an object. You'll need to fix your missing reference.
     

    Attached Files:

    Last edited: Jul 22, 2019
    bassmaMH likes this.
  16. bassmaMH

    bassmaMH

    Joined:
    May 20, 2018
    Posts:
    5
    Thanks a million! It worked. I have one question though: can I create a notification area that activates on collision with a FPS controller? I can’t seem to get it to work.
     
    Stephen_O likes this.
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Great I'm happy to hear it's working now.

    You can try the notification area's in the demo scene, bring your character into that scene and disable the original character. If your character does not work try comparing it to the character from the demo scene, it might be that your player's collider tag is not set to Player.
     
    bassmaMH likes this.
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I received this question in an email but the post is gone, I will answer it here anyway..

    I want to enable a canvas (that has a script ) when chatting with an NPC then immediately after the chat ends, disable it.

    You can use OnChatStart and OnChatStop events, assign the object you want enabled/disabled in these event fields and assign the GameObject.SetActive call.

     

    Attached Files:

  19. bassmaMH

    bassmaMH

    Joined:
    May 20, 2018
    Posts:
    5
    Hello Stephen :) Can I ask something? I need to disable mouselook on chat so that the fpc camera does not move around with the cursor (to be able to click on buttons freely). Is this option available in NPCChat? I tried disabling the fpc on chat but by doing so, I`m incapable of moving using the keyboard keys. Thank you.
     
  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Short answer is yes NPC Chat can toggle it on/off, but it needs to be available first.

    It will take a little bit of code editing to expose this to the inspector of the CharacterController and allow NPC Chat to toggle MouseLook on/off based on dialogue status.

    Add the following to MouseLook.cs

    Code (CSharp):
    1. public bool isActive = true;
    and update the LookRotation method in MouseLook.cs to check isActive

    Code (CSharp):
    1. public void LookRotation(Transform character, Transform camera)
    2. {
    3.     if (isActive)
    4.     {
    5.         float yRot = CrossPlatformInputManager.GetAxis ("Mouse X") * XSensitivity;
    6.         float xRot = CrossPlatformInputManager.GetAxis ("Mouse Y") * YSensitivity;
    7.  
    8.         m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
    9.         m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
    10.  
    11.         if (clampVerticalRotation)
    12.             m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
    13.  
    14.         if (smooth) {
    15.             character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
    16.                 smoothTime * Time.deltaTime);
    17.             camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
    18.                 smoothTime * Time.deltaTime);
    19.         } else {
    20.             character.localRotation = m_CharacterTargetRot;
    21.             camera.localRotation = m_CameraTargetRot;
    22.         }
    23.  
    24.         UpdateCursorLock ();
    25.     }
    26. }
    Add the following into FirstPersonController.cs

    Code (CSharp):
    1. public void MouseLook_Enable ()
    2. {
    3.     m_MouseLook.isActive = true;
    4. }
    5.  
    6. public void MouseLook_Disable ()
    7. {
    8.     m_MouseLook.isActive  = false;
    9. }

    Making these edits gives you a toggle in the FPSController inspector to turn on/off the MouseLook feature.

    MouseLookisActive.jpg

    Most importantly, it will also allow you to call MouseLook_Disable and MouseLook_Enable methods from the NPC Chat inspector using the OnChat & OnStopChat Events.

    NPCChatMouseLook.jpg
     
  21. Slowbud

    Slowbud

    Joined:
    Jul 19, 2015
    Posts:
    81
    Hello Stephen, after updating to the latest release I get following Error Message:

    UnassignedReferenceException: The variable _gameObject of ChatBox has not been assigned.
    You probably need to assign the _gameObject variable of the ChatBox script in the inspector.
    TurnTheGameOn.NPCChat.NPCChat.SetupChatBoxes () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:167)
    TurnTheGameOn.NPCChat.NPCChat.Awake () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:106)

    Here the code line:
    _NPCDialogue[ chatManager.currentDialogue[ nPCNumber ] ].page_ChatBox._gameObject.SetActive(false);
     
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510

    Hello, the error is stating that your `Chat Box` is missing a reference assignment, just assign the missing reference to fix the bug. This reference is what's used to toggle the chat box on/off during dialogue.

    You can reference any chat box from any demo scene in the asset, or the default chat box located at:
    Assets\TurnTheGameOn\NPC Chat\Resources\Default Chat Box.prefab
    assign its own gameobject to the `Game Object` field in the inspector and the dialogue should run without error.
     

    Attached Files:

  23. Slowbud

    Slowbud

    Joined:
    Jul 19, 2015
    Posts:
    81
    OK, I get rid of the error by putting in the Chatbox itself in the Game Object field.
    But can't get the NPC Chat to run after update at all. lt was working fine before. I even released a game version with it several times.

    I use "Use Distance Check" but no chats pops up anymore.

    I get following errors now:
    NullReferenceException
    TurnTheGameOn.NPCChat.NPCChat.NPCChatUpdate () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:273)
    TurnTheGameOn.NPCChat.NPCChat.NPCChatStart () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:388)

    Line 273: _NPCDialogue[ chatManager.currentDialogue[nPCNumber] ].page_ChatBox[currentPage].chatBoxComponents.buttonComponents[ia].buttonObject.SetActive(false);


    And:


    NullReferenceException: Object reference not set to an instance of an object
    TurnTheGameOn.NPCChat.NPCChat.CheckPlayerStatus () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:233)
    TurnTheGameOn.NPCChat.NPCChat.Update () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:122)

    Code line 233: chatText.text = "";

    I also have one Chat box which I usually open and close by code. To open I called: npcChat.NPCChatStart ();
    To close: npcChat.CloseChat ();

    When trying to open, I get the error in line 273

    When closing I get:
    NullReferenceException: Object reference not set to an instance of an object
    TurnTheGameOn.NPCChat.NPCChat.CloseChat () (at Assets/TurnTheGameOn/NPC Chat/Scripts/NPCChat.cs:342)
     
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Something I want to note is that, you should always backup your project(s) before directly importing a new asset store updates from any asset, or even just importing new content in general can sometimes cause projects to not work the same. Typically in code related assets, there might be optimizations or logic changes that will need to be manually changed in the project to support the update. I only recommend importing updates if there is something new you can't do without, or if you don't mind making the changes to stay up to date - and in this case always make a backup first so you can revert back in case something goes wrong.

    For NPC Chat, it's likely that most of these references are in the inspector - First thing to check is your NPC Chat inspector settings as well as checking the Chat Box object inspectors for any missing references and assign them - just like the previous bug from yesterday. You can reference the demo scene or the default chat box prefab to see how the chat boxes should be configured.

    Looking at the errors, these are all missing inspector chat box references that NPC Chat is trying to toggle on or off for dialogue. Compare your inspectors to the demo scene inspectors and you will be able to see what needs to be assigned.
     
  25. Slowbud

    Slowbud

    Joined:
    Jul 19, 2015
    Posts:
    81
    I'm doing backup. I even make a seperate backup each day of a week. Thats what you learn when doing an IT education ;-) Well, long ago :)
    Instead of writing that much about backup, you had could given me the hint that the menu buttons references were missing, which was the problem ;-) They are really good hidden in the chat box and were erased on the update. Anyway, all fine now :)
     
    Stephen_O likes this.
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Great, I'm glad your project is back up and working.
     
  27. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    275
    Hi i have a question,

    Came some new updates or features for this asset in the future?
     
    Stephen_O likes this.
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I want to refresh this asset really bad, it will likely happen after I finish my racing asset remake - maybe sometime next year for Unity 2019..

    I added a bunch of feature requests since releasing it, my main focus would be to first make it more intuitive and easier to use. Any additional feedback/requests would be greatly appreciated to help me know what some current use cases would be.
     
  29. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    275
    Good to hear, i think a god point will bring the cinemachine from unity to it.so the camera can fly in or give a other llok point when npc and player talking at the moment i use for that itween or camera spline.
    The Point for easier to use is important for me and my team at the moment and that is good to hear for us,cant wait for the new versions. Thx for your fast answer.
     
    Stephen_O likes this.
  30. kkfarrel

    kkfarrel

    Joined:
    Oct 31, 2018
    Posts:
    1
    Hi Stephen,

    I am having issues using this asset. It wouldn't work before or after the update. I followed the instructions exactly in the tutorial, but when my players collide, the chat does not pop up. I have used a debug log to make sure they are actually colliding and that it is being triggered and both are true. I am getting an error message here that you can see in the attached image. I saw the errors other folks got, but I couldn't understand the response as I am new to unity. Could you explain how I can fix this issue in layman's terms?
     

    Attached Files:

    Stephen_O likes this.
  31. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hi @kkfarrel , that line of code is triggering an error from the chat box text not being assigned in the ChatBox script inspector.

    Can you make sure that the option `Disable Script Rect Control` is enabled on the ChatBox inspector script to prevent the chat box from trying to auto scale? I attached a screenshot.

    I'm removing that functionality in the next update since Unity UI can do that by default, sorry for any confusion and the error.
     

    Attached Files:

    Last edited: Feb 18, 2019
  32. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.9 submitted.

    New User Manual

    • Requires 2018.3.7 or higher
    • Improved workflow
    • Improved inspectors
    • New demo scenes
    • New tutorials and documentation
    • "NPC Chat Options" moved to ScriptableObject to reduce the need to configure the same settings for multiple NPC Chat objects and having redundant variables in memory.
    • Unique "Chat Manager" references can now be assigned to "NPC Chat" objects, allowing for more control over how conversations can be structured and handled.
    • Added "disable" and "destroy" NPC Chat object on chat complete options.
    • Added "allow chat if other chat is active" option.

    Coming soon: I'll add a few more written tutorials to the user manual that covers topics not yet discussed, once done with that I'll make video versions.
     
    Last edited: Jul 22, 2019
    Pandur1982 likes this.
  33. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I see you moved up to 2018.4. What about those of us using 2017?
     
  34. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I've been moving all of my packages minimum to 2018.4 LTS to have a consistent procedure due to it being very hard and time consuming to know and make sure my Unity installs were secure and not vulnerable to CVE-2019-9197. https://unity3d.com/security

    I don't have time to check that every Unity version I had was properly patched and did not want to risk having my computer hacked due to this bug. Unity 5.x did not have a LTS version (which meant that only the patch would work, but I just don't trust it). So I decided to remove it from my machine since it was only used when I made an update to this package.

    For this reason, the recent updates went into 2018.4 LTS - it was either that or I deprecate the package and move on; I'd like to try to keep it alive so I settled on this scenario.

    If you don't want to update, you should keep using the version you are currently using - the recent update version 1.9.1 (to 2018.4 LTS) was only a missing material in the demo scene geometry.

    The previous package version 1.9 should still be available in your download archive, unless you deleted it or did not download it:

    C:\Users\userName\AppData\Roaming\Unity\Asset Store-5.x\TurnTheGameOn\Editor ExtensionsGUI\NPC Chat - Dialogue Event Trigger System

    If you need version 1.9 for Unity 5.6 and never had a chance to download it, you can email me stephen@turnthegameon.com with your invoice number and I'll send it over.
     
  35. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.9.2 submitted.

    • Added "Structured Dialogue Tutorial" to user manual.
    • Added "Structured Dialogue Tutorial" scene.
    • Added "Reset Chat Manager Index On Start" option to "NPC Chat Options". If enabled, the assigned Chat Manger will have the corresponding Conversation Index reset to 0 when the scene starts. This allows for NPCs to always use their first configured conversation when a scene starts - useful when creating structured/branching dialogue.
     
  36. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I am using Unity 2018.3.6.1
    It' s just a hair short of 2018.4 your current supported version. Will the current version of NPC chat work with that? Will it work with 1.9.1 and 1.9.2, or must I come up all the way to to 2018.4?
     
  37. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    You can try to bring it into 2018.3, I don't think that there would be any code issues, but you might need to rebuild the NPC Chat and Chat Box prefabs, materials might break too. You can have 2018.4 open for reference and 2018.3 open for a trial / reconfiguration if necessary.
     
  38. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    I moved up to Unity 2018.4. In the NPC Chat example 3, the ends of the longer lines of chat test do not display in the window. Do you know why?
     
  39. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    You can enable the Best Fit option on the Dialogue Text, this will resize the font to fit in the Text rect, or you can increase the size of the Text component's Rect Transform if you don't want your text size to shrink.

    Long dialogue.jpg
     
  40. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    A simpler fix seems to be to change the Vertical Overflow from "truncate" to "overflow." I prefer this because the Best Fit option does not adjust in advance, but changes size suddenly in front of the viewer.
     
    Stephen_O likes this.