I want to imply a dialog system to my game. I built a dialog system with SO nodes with a trigger option like that:
[CreateAssetMenu(fileName = "NewDialogNode", menuName = "Dialog System/Dialog Node")]
public class DialogNode : ScriptableObject {
public string text;
public List<DialogOption> options;
}
[System.Serializable]
public class DialogOption {
public string optionText;
public DialogNode nextNode;
public UnityEngine.Events.UnityEvent onOptionSelected;
}
But I cannot insert any GameObjects with their scripts and functions in the inspector.
It seems, as SO -Triggers field doesnt accept any GameObjects.
What did I wrong, or let’s go to the bigger picture, how should I design the DialogSystem, so I can imply a trigger like, pls trigger the’ start combat’ function of the enemyNPC.
What you’re experiencing is that objects in your assets cannot reference objects in your scenes.
A dialogue system that wants to reference objects in scenes would need to have the data baked directly into the scene itself. Otherwise you generally need to devise a way to indirectly reference scene objects.
Generally a dialogue system uses an actual node editing framework as it’s basis, which each node a more high-level and configurable operation. You can make your own with tools like Xnode or Unity’s Graphview, or use a ready-made node-based dialogue system from the asset store.
Note that a dialogue system doesn’t necessarily need to be specifically only about dialogue. Dialogue can be one portion to it, but the overarching system can be used to design common gameplay operations in a visually friendly manner.
When it comes to actually implementing nodes, usually there’s a common base interface or class that each node derives from, so they can all be referenced/serialised via said base type.
A very spitball example might look like:
public abstract class ActionNode : ScriptableObject
{
[SerializeField]
private ActionNode _nextNode
public ActionNode NextNode => _nextNode;
public abstract void ExecuteNode();
}
public class DialogueNode : ActionNode
{
[SerializeField]
private List<DialogueEntry> _enties = new();
public override void ExecuteNode()
{
DialogueSystem.OpenDialogue(dialogue: _enties, onDialogueCompleted: HandleDialogueCompleted);
}
private void HandleDialogueCompleted()
{
NextNode.ExecuteNode();
}
}
But of course this is mostly to illustrated the concept rather than how you might actually code it.
Even if you don’t end up using either of those, you could review them for structure because it is almost certain that they have already solved all the same problems you are trying to solve.