Page 1 of 2
Best practices and questions about Actor data
Posted: Sat May 30, 2020 8:23 am
by Ejbkt
I just acquired this asset, it sounds fantastic! I'm just having trouble integrating it into my game, and I'd like to ask for advice.
My game is a management-style game where you're a teacher with a class of students. Depending on their traits and your dialogue choices they'll perform differently in the classroom and have different dialogue "stories".
I was using ScriptableObjects to store character data for the students. Now I have this asset, I realize it may be easier to store their data in the Dialogue database instead, but I have a few questions:
1) Is it sensible to put all my character data in the Dialogue database?
2) How do I get a list of the Actors in C# code to use in a scene?
3) How would I sync a variable in my scene (say a "Student engagement level") with an Actor number field? So that if one changes, the other changes too.
4) Is it possible to put ScriptableObjects in a custom Actor field?
Thanks heaps!
Re: Best practices and questions about Actor data
Posted: Sat May 30, 2020 9:03 am
by Tony Li
Thanks for using the Dialogue System!
Ejbkt wrote: ↑Sat May 30, 2020 8:23 am1) Is it sensible to put all my character data in the Dialogue database?
Sure. You can define custom actor fields in the
Dialogue Editor's Templates section. In the Actors section, create an actor for each character and set the actor's field values. An advantage of doing this is that Dialogue System data, such as these field values, are included in saved game data, so you don't have to do anything extra to save them.
Ejbkt wrote: ↑Sat May 30, 2020 8:23 am2) How do I get a list of the Actors in C# code to use in a scene?
Use
DialogueManager.
masterDatabase:
Code: Select all
foreach (Actor actor in DialogueManager.masterDatabase.actors)
{
Debug.Log("Actor " + actor.Name + " is " + actor.LookupInt("Age") + " years old.");
}
Ejbkt wrote: ↑Sat May 30, 2020 8:23 am3) How would I sync a variable in my scene (say a "Student engagement level") with an Actor number field? So that if one changes, the other changes too.
If you maintain the value in an Actor number field, then in your script you can use a property instead of a variable. Use
DialogueLua.GetActorField() and GetActorField() to access the value:
Code: Select all
public class Student : MonoBehaviour
{
[Actor] public string actor; //<--(Can choose actor in inspector dropdown.)
public int EngagementLevel
{
get { return DialogueLua.GetActorField(actor, "Student engagement level").asInt; }
set { return DialogueLua.SetActorField(actor, "Student engagement level", value); }
}
}
That's just one way of approaching it. Alternatively, if you want to keep the value in your script instead of the dialogue database, you can write C# methods to get and set the value. Then register those methods with the Dialogue System so conversations' Conditions and Script fields can use them.
Ejbkt wrote: ↑Sat May 30, 2020 8:23 am4) Is it possible to put ScriptableObjects in a custom Actor field?
No. To support full export/import with external editors such as Chat Mapper, articy:draft, and Twine, dialogue databases don't contain any Unity-specific asset types, with the exception of actors pointing to portrait images. (Those are handled specially.)
However, in the upcoming version 2.2.7, each dialogue entry node can have a UnityEvent to which you can assign scene objects. So dialogue entry nodes can work with scripts in a scene.
Re: Best practices and questions about Actor data
Posted: Sat May 30, 2020 9:22 am
by Ejbkt
Thank you very much, that is a huge help! =)
Re: Best practices and questions about Actor data
Posted: Sat May 30, 2020 10:33 am
by Tony Li
Happy to help!
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 5:43 am
by s0963123
I have similar question too.
I have added a custom field [location] for all my actors.
I want to go through all the actors to find which one has/is in certain location.
I have playmaker too, if I only have one actor, I could simply use: Get Lua Field.
But since there would be over 100 actors, what is the best way to do it?
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 9:10 am
by Tony Li
Hi,
In a C# script, you could do this:
Code: Select all
foreach (var actor in DialogueManager.masterDatabase.actors)
{
if (DialogueLua.GetActorField(actor.Name, "location").asString == "Certain Location")
{
Debug.Log(actor.Name + " is in Certain Location");
}
}
Here's a new PlayMaker action that gets an array of all actor names (or all quest names, or all variable names, etc.):
DS_PlayMakerSupport_2020-06-30.unitypackage
(EDIT: Replaced with full integration package.)
Once you have the array, you can loop through it in PlayMaker and use the GetLuaField action to find the actor(s) in the certain location.
This action will also be in the updated PlayMaker Support package in DS version 2.2.8.
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 6:24 pm
by s0963123
Tony Li wrote: ↑Tue Jun 30, 2020 9:10 am
Here's a new PlayMaker action that gets an array of all actor names (or all quest names, or all variable names, etc.):
Nice to hear that. I think it would be of great help. Any plan on when to release DS version 2.2.8 ?
I import the package to try out but it return this error message:
Assets\Pixel Crushers\Dialogue System\Third Party Support\PlayMaker Support\Actions\GetAllLuaElements.cs(14,10): error CS0246: The type or namespace name 'LuaElementTypeEnum' could not be found (are you missing a using directive or an assembly reference?)
Any quick fix for that? If not, I could just wait for 2.2.8.
Thanks again.
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 8:51 pm
by Tony Li
Oops, I tried to minimize the file size by selectively exporting files, and I missed one. Here's the entire PlayMaker Support package, which isn't big either:
DS_PlayMakerSupport_2020-06-30.unitypackage
DS 2.2.8 should be out in mid-July.
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 9:43 pm
by s0963123
new error :
Assets\Pixel Crushers\Dialogue System\Third Party Support\PlayMaker Support\Actions\GetAllLuaElements.cs(65,117): error CS0117: 'QuestState' does not contain a definition for 'Grantable'
Re: Best practices and questions about Actor data
Posted: Tue Jun 30, 2020 10:34 pm
by Tony Li
Hi,
Can you update to a newer version of the Dialogue System? The "Grantable" quest state was added a few versions back.