Conversation On Trigger Enter issue.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
kilfeather94
Posts: 17
Joined: Sat Jan 23, 2016 1:35 pm

Conversation On Trigger Enter issue.

Post by kilfeather94 »

I'm just having a problem in regards to starting a conversation upon entering an NPC's trigger. I have the script 'Set Component Enabled On Dialogue Event' so that the player's scripts which are used to control and move the player are disabled when a conversation starts. This works perfectly when I'm triggering a conversation through 'On Use'. But if I start a conversation through ' On Trigger Enter', when the player walks into the NPC's trigger, the player will keep walking forward, even though the player's scripts have been disabled, which I checked in the inspector on runtime. Has anyone else experienced this problem and if so, is there a solution?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation On Trigger Enter issue.

Post by Tony Li »

Hi,

If you switch the trigger back to On Use and trigger the conversation while running at full speed toward the NPC, do you get the same problem?

If so, perhaps you need to do something more than just disable the script, such as stopping root motion animation. If it's just stuck in the wrong animation state, you can add a Set Animator State On Dialogue Event component to your player to transition to an idle state.

If it's more complicated than animation, you can add a custom script that has an OnConversationStart method.

If neither of those suggestions help, please feel free to send an example to tony (at) pixelcrushers.com. I'll be happy to take a look.
kilfeather94
Posts: 17
Joined: Sat Jan 23, 2016 1:35 pm

Re: Conversation On Trigger Enter issue.

Post by kilfeather94 »

Yeah, when I switched back to 'On Use' and triggered the animation while running at full speed, the same issue happened. My 'idle' animation is inside a Blend Tree. The Blend Type is 2D freeform cartesian, with parameters 'Turn' and 'Forward'. It is in Idle when the 'Forward' parameter is at 0.

I'm not entirely sure how the 'Set Animator State on Dialogue Event' script works. For the 'On Start' part of this script, what should the state name be if I'm using a blend tree that has the idle animation inside it. And also, does 'cross fade duration' apply in this case?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation On Trigger Enter issue.

Post by Tony Li »

The 'Set Animator State On Dialogue Event' component only switches states. It doesn't touch animator parameter values.

Would it be possible to add another Idle state for conversations that only plays the idle clip? Then you could configure the component like this:

Image

(Cross Fade Duration is the time in second that it blends between the player's current state and new state.)

If not, you'll need to write a small script. Something like:

Code: Select all

using UnityEngine;

public class IdleOnConversationStart : MonoBehaviour {

    public void OnConversationStart(Transform actor) {
        GetComponent<Animator>().SetFloat("Forward", 0);
    }
}
kilfeather94
Posts: 17
Joined: Sat Jan 23, 2016 1:35 pm

Re: Conversation On Trigger Enter issue.

Post by kilfeather94 »

Just tried the first option you suggested and added a separate Idle state and that worked :) Thanks very much for the help and quick response.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation On Trigger Enter issue.

Post by Tony Li »

Happy to help! :-)
Post Reply