"Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Lauri K
Posts: 8
Joined: Tue Aug 04, 2020 3:08 pm

"Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Lauri K »

Hi,

I bumped into interesting but troublesome issue. My setup:

1) I have a scene called "Logic" where I hold the Player (named as "Pilot")
2) I have a scene called "Enemies" where I hold the NPC (named as "Geologist")
3) I have a Player in the Logic scene, having a Proximity Selector and Dialogue Actor components
4) I have an NPC in the Enemies scene, having a Dialogue Actor, Dialogue Trigger and Usable components
5) I am passing the Player Transformation via FSM Playmaker script, using "Set Property" and passing the Player's Transform as the "Conversation Conversant" to the NPC's Dialogue Trigger. I am getting this Transform to show up nicely in the inspector (see screenshot)
inspectorview.JPG
inspectorview.JPG (176.45 KiB) Viewed 565 times

So, the problem. When I trigger the NPC dialogue with the Use-button, the dialogue starts correctly, but here comes the weird issue: I have the "Conversation Actor" set to be the NPC/Geologist's Dialogue Actor's Transform, and "Conversation Conversant" set to Player Actor's Transform, which I get from another scene with PlayMaker. All looks good, the NPC's Dialogue Actor gets both transforms correctly as the photo shows.

Then, I have set the "Stop Conversation if too far", with value 5 (meters, tried with other numbers too). But what ever I do, the conversation doesn't stop if I walk away from it, much further than 5 meters. The ONLY way so far I have figured out to get it working, is to swap the "Conversation Conversant" and "Conversation Actor" in the NPC's Dialogue Actor. I mean, literally just swap their places: put the Player as the Actor and NPC as the Conversant. Then the "Stop Conversation if too far" starts working. But this is a new issue, because then the dialogue comes from wrong Dialogue Actors, i.e. the Player starts to talk NPC's dialogue and vice versa. All the dialogue is automated/imported from CSV so I wouldn't want to start rearranging anything / make a quick fix; I would need to get it working as in the screenshot. NPC being the Actor and Player being the conversant, but the "Stop if too far" still working. I didn't really find good information how that function should work...Am I doing something incorrectly?

I can repeat this issue. Somehow I'm suspecting, that the Transform I get from cross-scene has to be placed in the ACTOR transform, and not to the CONVERSANT transform. I just don't know why it would matter. Could you help?

Cheers!
Lauri
User avatar
Tony Li
Posts: 21965
Joined: Thu Jul 18, 2013 1:27 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Tony Li »

Hi Lauri,

As you've noticed, the Dialogue System Trigger's "Stop Conversation If Too Far" option monitors the distance between the Conversation Actor and the Dialogue System Trigger itself. (I'll clarify this in the next update's documentation.)

If you want to monitor the distance between any two conversation participants, add this script to one of them:

MonitorConversationDistance.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class MonitorConversationDistance : MonoBehaviour
{
    public float maxConversationDistance = 5;

    private Transform otherParticipant = null;

    private void OnConversationStart(Transform other)
    {
        otherParticipant = other;
    }

    private void OnConversationEnd(Transform other)
    {
        otherParticipant = null;
    }

    private void Update()
    {
        if (otherParticipant != null && Vector3.Distance(transform.position, otherParticipant.position) > maxConversationDistance)
        {
            DialogueManager.StopConversation();
        }
    }
}
Lauri K
Posts: 8
Joined: Tue Aug 04, 2020 3:08 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Lauri K »

Hi Tony,

perfect. This is what I was fighting with and it's now fixed. Great if you can update the manual, at least for me was a bit unclear how the distance measuring works. Thanks a lot!

Cheers,
Lauri
User avatar
Tony Li
Posts: 21965
Joined: Thu Jul 18, 2013 1:27 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Tony Li »

Glad to help! I've already staged that additional info in the documentation for the next release.
Lauri K
Posts: 8
Joined: Tue Aug 04, 2020 3:08 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Lauri K »

Great, thanks for updating the documentation, always beneficial.

Still, I am wondering a problem related to my same setup. I started thinking why I even need to pass any transforms of the characters, as there is the "Stop Conversation on Trigger Exit" feature in Dialogue Manager. So I tried to do this:

I have a DialogueSystemTrigger using OnTriggerEnter to trigger a conversation, and it triggers the conversation nicely with my player, who is located in another scene in Unity (loaded additive when Play mode). And everything works without passing any transforms etc. between scenes. BUT when I tick the Stop Conversation On Trigger Exit, nothing happens. The conversation goes on even when running outside of the NPCs trigger.

So why OnTriggerEnter triggers the conversation, but OnTriggerExit selection doesn't do anything? What Am I missing?

Screenshot of my setup attached:
DialogueSystemTrigger setup.JPG
DialogueSystemTrigger setup.JPG (116.95 KiB) Viewed 543 times
Lauri K
Posts: 8
Joined: Tue Aug 04, 2020 3:08 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Lauri K »

...as a further information I made a workaround (for now) with following steps:

1) Added a second Dialogue System Trigger component
2) Marked it to trigger "On Trigger Exit"
3) Registered a new Lua function "StopTalking" (script below)
4) Run this "StopTalking" On the trigger exit.

Seems a bit overkill, as the Dialogue System Trigger has the formal "Stop Conversation On Trigger Exit", but like I wrote on my previous post, that doesn't seem to work for some reason.

My workaround code:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class RegisterLuaComponents : MonoBehaviour
{

    void OnEnable()
    {
        Lua.RegisterFunction("StopTalking", this, typeof(RegisterLuaComponents).GetMethod("StopTalking"));
    }

    void OnDisable()
    {
        Lua.UnregisterFunction("StopTalking");
    }

    public void StopTalking()
    {
        PixelCrushers.DialogueSystem.DialogueManager.StopConversation();
    }
}
workaround.JPG
workaround.JPG (214.94 KiB) Viewed 541 times
User avatar
Tony Li
Posts: 21965
Joined: Thu Jul 18, 2013 1:27 pm

Re: "Stop Conversation if too far" problem with cross-scene transformations passed with FSM PlayMaker

Post by Tony Li »

Hi,

The Dialogue System Trigger's Stop Conversation On Trigger Exit has these requirements:
  • The GameObject that is exiting the Dialogue System Trigger's trigger collider must be either of the GameObjects involved in the conversation (actor or conversant).
  • At least 0.2 seconds must have passed since the conversation started. (If you're pausing the game during conversations, no time will have passed, so it will not pass this requirement.)
You can temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. This will report which GameObjects are involved in the conversation. Look for a log similar to this:

Dialogue System: Starting conversation 'Title' with actor=X and conversant=Y

The GameObject X or Y must exit the Dialogue System Trigger's trigger collider for Stop Conversation On Trigger Exit to work.
Post Reply