Share the same Dialogue, but different condition per Actor
Share the same Dialogue, but different condition per Actor
Hello, let me explain my setup :
I have a Conversation setup with multiple dialogues. They all come from the START node with different conditions.
for example :
GenericDialogue:
START -> (if X == 1) "Line A"
START -> (if X== 2) "Line B"
START -> (if X== 3) "Line C"
START -> (if X== 4) "Line D"
...
This Dialogue is always said by the same Actor, called "ActorA"
In my Scene I multiple instance "ActorA".
Each one of those actor, has a c# defining some logic, and a unique value X.
How can have each actor check its own unique value X when I launch the converstation from this actor ?
I tried registering a custom Lua Function "GetValueofX" returning the Value of X, but it doesnt work with multiple instance of the same actor of course.
Is there a better way to do that ?
PS : I thought about creating custom variable, Its not viable to create one variable for each unique actor in my project
Thank you, and I really love this tool !
If you are interested, here is the game I am making with it :
I have a Conversation setup with multiple dialogues. They all come from the START node with different conditions.
for example :
GenericDialogue:
START -> (if X == 1) "Line A"
START -> (if X== 2) "Line B"
START -> (if X== 3) "Line C"
START -> (if X== 4) "Line D"
...
This Dialogue is always said by the same Actor, called "ActorA"
In my Scene I multiple instance "ActorA".
Each one of those actor, has a c# defining some logic, and a unique value X.
How can have each actor check its own unique value X when I launch the converstation from this actor ?
I tried registering a custom Lua Function "GetValueofX" returning the Value of X, but it doesnt work with multiple instance of the same actor of course.
Is there a better way to do that ?
PS : I thought about creating custom variable, Its not viable to create one variable for each unique actor in my project
Thank you, and I really love this tool !
If you are interested, here is the game I am making with it :
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
Previous game made with Dialogue system ->The Spirit and The mouse<-
Re: Share the same Dialogue, but different condition per Actor
Very cool! That is a great looking game with a clear and interesting hook.
Let's assume ActorA is defined in the dialogue database's Actors section. ActorA is also assigned to the conversation as the conversation actor.
In your Dialogue System Trigger, if you do not assign a GameObject to the Conversation Actor field, it will:
However, if you assign a different GameObject with a Dialogue Actor component set to a different actor, or to an actor name that doesn't exist in the database, it will set Variable["Actor"] to that actor name.
(More info: Character GameObject Assignments)
Your conversation's Conditions can check the value of Variable["ActorIndex"] -- or Variable["ConversantIndex"] if you're assigning the GameObject to the Conversation Conversant field.
Let's assume ActorA is defined in the dialogue database's Actors section. ActorA is also assigned to the conversation as the conversation actor.
In your Dialogue System Trigger, if you do not assign a GameObject to the Conversation Actor field, it will:
- Look for a GameObject with a Dialogue Actor component set to ActorA.
- Failing that, look for a GameObject named ActorA.
- Failing that, not assign a GameObject at all.
However, if you assign a different GameObject with a Dialogue Actor component set to a different actor, or to an actor name that doesn't exist in the database, it will set Variable["Actor"] to that actor name.
(More info: Character GameObject Assignments)
Your conversation's Conditions can check the value of Variable["ActorIndex"] -- or Variable["ConversantIndex"] if you're assigning the GameObject to the Conversation Conversant field.
Re: Share the same Dialogue, but different condition per Actor
Thanks a lot, I think i understand a lot more now !
I understand that now, I can assign the gameobject of the specific actor in the dialogue trigger. (the shopkeeper example from the doc is great)
I am a very visual person, so I still have a bit of trouble understanding everything...I added some picture showing exactly my setup, It would be amazing if you could give me some guidance on this.
In the scene : Multiple instances of the same prefab. they all have a dialogue system trigger component + an c# script for some logic, let's call this component "ActorX"
The StartConversation > Converstation Actor is set to the this gameobject
in this script, I naively tried to make a lua function to be able to access the data of this instance in a conversation
And here is how the conversation those actor should all use is setup (using a Generic "ActorX" actor)
What I want : every dialogue condition should check a variable in the ActorX component of the object that started the conversation (a variable named "current_state" in this example).
However the lua condition will call this function globally and not for the current actor right ?
edit : for a more concrete example, imagine a Shopkeeper converstation with two entry : "Hello What would you like to buy ?", and "Hello, I dont have money anymore sorry".
Each shopkeeper in the game would have a script called Shopkeeper.cs, with a property int Money
Following the same pattern : how to have each shopkeeper check for the value of his own money in the conversations conditions when starting the dialogue to start from the right entry ?
thanks again for the great support
I understand that now, I can assign the gameobject of the specific actor in the dialogue trigger. (the shopkeeper example from the doc is great)
I am a very visual person, so I still have a bit of trouble understanding everything...I added some picture showing exactly my setup, It would be amazing if you could give me some guidance on this.
In the scene : Multiple instances of the same prefab. they all have a dialogue system trigger component + an c# script for some logic, let's call this component "ActorX"
The StartConversation > Converstation Actor is set to the this gameobject
in this script, I naively tried to make a lua function to be able to access the data of this instance in a conversation
And here is how the conversation those actor should all use is setup (using a Generic "ActorX" actor)
What I want : every dialogue condition should check a variable in the ActorX component of the object that started the conversation (a variable named "current_state" in this example).
However the lua condition will call this function globally and not for the current actor right ?
edit : for a more concrete example, imagine a Shopkeeper converstation with two entry : "Hello What would you like to buy ?", and "Hello, I dont have money anymore sorry".
Each shopkeeper in the game would have a script called Shopkeeper.cs, with a property int Money
Following the same pattern : how to have each shopkeeper check for the value of his own money in the conversations conditions when starting the dialogue to start from the right entry ?
thanks again for the great support
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
Previous game made with Dialogue system ->The Spirit and The mouse<-
Re: Share the same Dialogue, but different condition per Actor
Hi,
My previous reply suggested using Variable["ActorIndex"] to differentiate the actors.
However, reading your second reply, a Lua function is probably a good solution. Here's one way you could implement it:
ActorX.cs
GetActorStateLuaFunction.cs
Then you can use "GetActorState() == 0" etc. in your dialogue entry nodes' Conditions fields.
My previous reply suggested using Variable["ActorIndex"] to differentiate the actors.
However, reading your second reply, a Lua function is probably a good solution. Here's one way you could implement it:
ActorX.cs
Code: Select all
using UnityEngine;
public class ActorX : MonoBehaviour // Add to each ActorA instance, and set current_state uniquely on each.
{
public int current_state;
}
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class GetActorStateLuaFunction : MonoBehaviour // Add to the Dialogue Manager GameObject.
{
void Awake()
{
Lua.RegisterFunction("GetActorState", this, SymbolExtensions.GetMethodInfo(() => GetActorState()));
}
double GetActorState() // (Lua functions use doubles for numbers)
{
if (DialogueManager.currentActor == null) return -1; // Default to -1.
var actorX = DialogueManager.currentActor.GetComponent<ActorX>();
if (actorX == null) return -1;
return actorX.current_state;
}
}
Re: Share the same Dialogue, but different condition per Actor
Thanks you so much tony, this look EXACTLY like what I needed !
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
Previous game made with Dialogue system ->The Spirit and The mouse<-
Re: Share the same Dialogue, but different condition per Actor
Im sorry to spam this, but it seems my DialogueManager.currentActor returns null, even with the DIalogue actor component correctly set
Do you know what could cause that ?
EDIT : actually, only actor I managed to get in DialogueManager.currentActor, seems to be the Player itself
EDIT2 :I think I found the solution from here http://www.pixelcrushers.com/phpbb/view ... 223&p=6531
I call all my dialogue with a Selector from my player, looks like the conversation actor is always the player, even though I assigned an object in the target Dialogue System triger of an actor
Do you know what could cause that ?
EDIT : actually, only actor I managed to get in DialogueManager.currentActor, seems to be the Player itself
EDIT2 :I think I found the solution from here http://www.pixelcrushers.com/phpbb/view ... 223&p=6531
I call all my dialogue with a Selector from my player, looks like the conversation actor is always the player, even though I assigned an object in the target Dialogue System triger of an actor
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
Previous game made with Dialogue system ->The Spirit and The mouse<-
-
- Posts: 9
- Joined: Sat Apr 27, 2019 5:14 am
Re: Share the same Dialogue, but different condition per Actor
I found this very illuminating and your game looks amazing already! Liked and subscribed.
Re: Share the same Dialogue, but different condition per Actor
Thanks !! I finally fixed all my issue thanks to the support
I admit the whole Conversation Actor / Converstant is a bit confusing to me, especially because in my game the Player never speak, like in Zelda game for example
I admit the whole Conversation Actor / Converstant is a bit confusing to me, especially because in my game the Player never speak, like in Zelda game for example
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
Previous game made with Dialogue system ->The Spirit and The mouse<-
Re: Share the same Dialogue, but different condition per Actor
Hi,
I'm glad you got it all working. You can still assign the Player as the Actor but just never use it as the speaker of any nodes.
Or you can assign different actors, and not assign the Player to the conversation at all. However, in this case you'll need to find ActorX some way other than DialogueManager.currentActor.
Just adding that, although it sounds like you have a working solution already. Please keep us updated on the game if you remember and have time!
I'm glad you got it all working. You can still assign the Player as the Actor but just never use it as the speaker of any nodes.
Or you can assign different actors, and not assign the Player to the conversation at all. However, in this case you'll need to find ActorX some way other than DialogueManager.currentActor.
Just adding that, although it sounds like you have a working solution already. Please keep us updated on the game if you remember and have time!