Greetings!
I've recently picked up the dialogue system for unity and it looks like its massively going to help my project so thank you for creating the tool. I am however having an issue I can't work out.
I'm working through creating a Prefab for all the enemies in my game; setting it up with every generic script/collider/etc I can before customising them later. One of these prefabs is a Dialogue System Trigger to 'catch' the player and start a conversation so they can be thrown out of the area.
I can set up the trigger to start the conversation when they are close. But I need to also check a bool to confirm if the enemy can see the player. A dialogue database variable (bool) would become true if any enemy could see the player, so I could end up with a false positive. What would the best method be to have the Dialogue System Trigger check a bool from a script attached to the same GameObject (or parent of)?.
Thanks in Advance,
Rob
Prefab Dialogue trigger System using script variables
Re: Prefab Dialogue trigger System using script variables
I recommend writing a C# method that returns the value of the bool, something like CanSeePlayer("NPC"). Given an NPC name, it returns the bool on that NPC's script. If each NPC has a Dialogue Actor component, you can quickly look up the NPC by calling CharacterInfo.GetRegisteredActorTransform("NPC Name"). Then register it with Lua and call it in the Conditions > Lua Conditions. Example:
Code: Select all
public static bool CanSeePlayer(string npcName)
{
var myScript = CharacterInfo.GetRegisteredActorTransform(npcName).GetComponent<MyScript>();
return myScript.myBool; // (Ideally you'll add some null-checking, which I omitted for clarity.)
}
void Awake()
{ // Register function with Lua:
Lua.RegisterFunction("CanSeePlayer", null, SymbolExtensions.GetMethodInfo(() => CanSeePlayer(string.Empty)));
}
Re: Prefab Dialogue trigger System using script variables
Thank you so much for your help.
I had been looking through the manual and was trying to get the LUA functions scripting to work, but was struggling. The example you gave was exactly what I needed. It's set up now so I should just be able to copy paste the enemy and change the Actor name + the corresponding LUA condition search name.
As a quick follow up question. If I wanted to trigger script at the end of that specific conversation, my first thought would be to set a variable via an action on that conversation triggering. Then using a script to trigger 'OnConversationEnd' if it's true. Does that sound about right?
Again cheers for the help, you seem pretty invaluable to the people using this tool .
I had been looking through the manual and was trying to get the LUA functions scripting to work, but was struggling. The example you gave was exactly what I needed. It's set up now so I should just be able to copy paste the enemy and change the Actor name + the corresponding LUA condition search name.
As a quick follow up question. If I wanted to trigger script at the end of that specific conversation, my first thought would be to set a variable via an action on that conversation triggering. Then using a script to trigger 'OnConversationEnd' if it's true. Does that sound about right?
Again cheers for the help, you seem pretty invaluable to the people using this tool .
Re: Prefab Dialogue trigger System using script variables
You can add a script with an OnConversationEnd(Transform) method to the NPC. The Dialogue System will automatically call the method at the end of the conversation.
Re: Prefab Dialogue trigger System using script variables
Cheers! That makes things pretty simple.
One final question, is there a reason why the C Sharp method would return false after the scene has been reloaded?
The method is triggering and the source bool is true, but the condition is showing as false, resulting in the conversation not triggering second time round.
Sorry to continually send these questions, I'm just not seeing where the scripts are failing to communicate correctly.
One final question, is there a reason why the C Sharp method would return false after the scene has been reloaded?
The method is triggering and the source bool is true, but the condition is showing as false, resulting in the conversation not triggering second time round.
Sorry to continually send these questions, I'm just not seeing where the scripts are failing to communicate correctly.
Re: Prefab Dialogue trigger System using script variables
Are there any messages in the Console window?
Try adding some Debug.Log lines to your C# method to give you an idea of what it's doing, or set a debugger breakpoint and step through it.
You can also add a Lua Console component to your scene. Press ~+L to open the Lua Console, then enter:
to see the result of checking that function. Maybe "Bob" is no longer registered for some reason after reloading the scene.
Alternatively to using a Lua Console, you can use the Dialogue Editor's Watches tab. There's a "Run Lua Code" field at the bottom of editor on that page..
Try adding some Debug.Log lines to your C# method to give you an idea of what it's doing, or set a debugger breakpoint and step through it.
You can also add a Lua Console component to your scene. Press ~+L to open the Lua Console, then enter:
Code: Select all
return CanSeePlayer("Bob")
Alternatively to using a Lua Console, you can use the Dialogue Editor's Watches tab. There's a "Run Lua Code" field at the bottom of editor on that page..
Re: Prefab Dialogue trigger System using script variables
I finally figured out the problem (After a couple of hours this morning not the entire past week).
The character name that the LUA condition was looking for had at some point been added as a character name to the list of Actors in the database. Although it had been deleted I think it was defaulting to this old reference on reloading the scene. The issue didn't happen if I used new names that had never been added to the actor field.
At least this is what I think was happening. If so how do I delete any past reference to these names from that database? Since they aren't in the Actor list any more but are still affecting scripts.
If I am off on what I think is the cause then let me know, but using new names did fix the issue.
Cheers,
Rob
The character name that the LUA condition was looking for had at some point been added as a character name to the list of Actors in the database. Although it had been deleted I think it was defaulting to this old reference on reloading the scene. The issue didn't happen if I used new names that had never been added to the actor field.
At least this is what I think was happening. If so how do I delete any past reference to these names from that database? Since they aren't in the Actor list any more but are still affecting scripts.
If I am off on what I think is the cause then let me know, but using new names did fix the issue.
Cheers,
Rob
Re: Prefab Dialogue trigger System using script variables
Hi Rob,
You can use the Dialogue Editor's Global Search & Replace feature, available on the Database tab.
You can use the Dialogue Editor's Global Search & Replace feature, available on the Database tab.