Best way to keep data in the editor (profession data for simple AI)

I am making a really simple rts style building game where I have villagers walking around and doing different tasks according to a player assigned profession (a bit like gnomoria profession system but simpler). Right now they have one job, builder, and it is hard coded in the villager script.

I want the player to be able to assign profession to villagers. I have a general idea of what data I need to know about each profession (the name, description, tasks that can be done by that profession, ect), and know how to get the villager to do what I want. But I dont know what is the best way to “save” this data. Should I create a “profession” class that contain all info and related task and then add each profession to a List somewhere that I can edit in the editor ? Maybe create a separate script for each profession that can be added to a list inside my villager script and then edited by the player ingame ?

A good way to save profession data would be to save each profession as a ScriptableObject.

Indeed, as you suggested, you should start by creating a “Profession” class. This class must extend ScriptableObject, and must have the [System.Serializable] attribute, which will enable you to save instances of the class as files.

`
[System.Serializable]
[CreateAssetMenu]
public class Profession : ScriptableObject {

//No idea what your class would need, so here’s some sample data

 public string Name = "";

 public float salary;

}`

(Note the [CreateAssetMenu] attribute. This will enable you to create Profession files from Unity’s Create menu.)

Once you’ve got the Professions, add a Profession property to your villager component(s):

`
[SerializeField] Profession myProfession;

public void SetProfession (Profession p) {

     myProfession = p;

     //Probably something to make the villager respond to the change

}`

…and have a List of Professions for the player to access in-game, again as you suggested. When the player assigns a villager a new profession, just call that villager’s SetProfession function, passing as an argument the Profession object selected from the List.

On that note, depending on what exactly you need, the List could also be stored as a ScriptableObject. Aside from storing the data independently from any prefabs or anything, you could also have multiple lists this way…say, if you wanted to have a list for level 1 professions, and a list for level 2 professions, etc.

What I ended up doing is this : I did away with the profession class entirely and kept only the task. I made a task class that contain a profession enum, a task name, a description and a bool. I made a “master” list of all task in the editor and saved it to a xml file just in case it get erased by the editor (that file is not used by the game at runtime. Its jut that I don’t want to have to remake it if something happens). That task list is used to create a “create job” ui where the player see on one side a list of profession with the attached tasks with a checkbox beside each one and on the other side, a list of currently activated task. When one task is checked, it is copied to a activated task list. The order of the list is the priority and can be changed by using buttons on the side of the list. It works very well and is mutch simpler then my original solution.