Announcements, support questions, and discussion for the Dialogue System.
Abelius
Posts: 318 Joined: Fri Jul 21, 2017 12:45 pm
Post
by Abelius » Thu Feb 08, 2024 1:44 pm
Hi there,
I needed to get the game object associated with the current speaker and/or listener in an active convo, and after some research, including one of my old posts (deja vu feeling here), I've figured out a solution to use from a PlayMaker CallMethod action...
Here's the code I've used:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class GetCurrentSpeakerListener : SequencerCommand
{
public GameObject CurrentSpeaker()
{
if (!DialogueManager.isConversationActive) return null;
Transform subject = GetSubject("speaker");
return subject.gameObject;
}
public GameObject CurrentListener()
{
if (!DialogueManager.isConversationActive) return null;
Transform subject = GetSubject("listener");
return subject.gameObject;
}
}
}
It's working and that's great, but I'd still like a sanity check from you, Tony.
Thanks.
Unity 2019.4.9f1
Dialogue System 2.2.15
Tony Li
Posts: 22110 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Thu Feb 08, 2024 4:57 pm
Hi,
In a sequencer command script, you can just use the properties speaker and listener . They'll already be defined for you.
Abelius
Posts: 318 Joined: Fri Jul 21, 2017 12:45 pm
Post
by Abelius » Fri Feb 09, 2024 10:51 am
I'm not sure what you mean.
What I need is to get the GO of the speaker and the listener inside a PlayMaker FSM, not running a sequencer command.
Do you mean those are already defined in another place? Can I get them running a LUA command from PlayMaker or something like that?
Thanks.
Ps.: BTW, the above script has mysteriously stopped working today. I don't have a clue why.
Unity 2019.4.9f1
Dialogue System 2.2.15
Tony Li
Posts: 22110 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Fri Feb 09, 2024 11:01 am
Hi,
Did you paste in the code that you intended to show? It looks like it's an implementation of the SequencerCommand command. Maybe you meant:
Code: Select all
public class GetCurrentSpeakerListener : MonoBehaviour
In the general case, you can get the current speaker and listener's GameObjects like this:
Code: Select all
public GameObject CurrentSpeaker()
{
if (!DialogueManager.isConversationActive) return null;
return DialogueManager.currentConversationState.subtitle.speakerInfo.transform.gameObject;
}
public GameObject CurrentListener()
{
if (!DialogueManager.isConversationActive) return null;
return DialogueManager.currentConversationState.subtitle.listenerInfo.transform.gameObject;
}
Abelius
Posts: 318 Joined: Fri Jul 21, 2017 12:45 pm
Post
by Abelius » Fri Feb 09, 2024 11:54 am
Great! It's working again with your code.
The only reason for the namespace and why it inherited from SequencerCommand is because I ripped the thing from a current script I had, related to those. But yeah, this is much better and straightforward.
I knew it was a good idea to check with you.
Thank you!
Unity 2019.4.9f1
Dialogue System 2.2.15