Table of Contents

Class DialogueTemplate

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

A CachedScriptableObject that defines a complete dialogue tree. Contains all dialogue nodes, branching choices, and ECA conditions/actions. Assigned to NPCs via DialogueInteractable.

[CreateAssetMenu(fileName = "New Dialogue", menuName = "FishMMO/Dialogue/Dialogue Template", order = 0)]
public class DialogueTemplate : CachedScriptableObject<DialogueTemplate>, ICachedObject
Inheritance
Object
ScriptableObject
DialogueTemplate
Implements
Inherited Members
ScriptableObject.SetDirty()
ScriptableObject.CreateInstance<T>()
Object.GetEntityId()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.ToString()
Object.name
Object.hideFlags

Fields

CacheDialogueChoices

When true, the server preserves dialogue choice selections across interactions so the client cannot repeat or abuse quest/story-driven dialogue choices.

[Tooltip("When enabled, the server remembers which choices each character has made in this dialogue.")]
public bool CacheDialogueChoices

Field Value

bool

Description

Description of the dialogue, used for editor notes.

[TextArea(2, 4)]
public string Description

Field Value

string

IconReference

Addressable reference to the icon sprite for this dialogue.

public AssetReferenceSprite IconReference

Field Value

AssetReferenceSprite

MaxTrackedChoices

Maximum number of trackable choices per template using a short bitmask.

public const int MaxTrackedChoices = 16

Field Value

int

Nodes

All dialogue nodes in this template.

public List<DialogueNode> Nodes

Field Value

List<DialogueNode>

StartNodeId

The node ID where the dialogue starts.

public int StartNodeId

Field Value

int

Properties

Icon

The icon for this dialogue (loaded at runtime on client).

public Sprite Icon { get; }

Property Value

Sprite

Name

The name of the dialogue template (from the ScriptableObject asset name).

public string Name { get; }

Property Value

string

Methods

BuildNodeMap()

Builds a lookup dictionary from node ID to DialogueNode for fast runtime access.

public Dictionary<int, DialogueNode> BuildNodeMap()

Returns

Dictionary<int, DialogueNode>

Dictionary mapping node IDs to their DialogueNode instances.

GenerateNodeId()

Generates the next available node ID for the dialogue tree.

public int GenerateNodeId()

Returns

int

An unused node ID.

GetChoiceBitIndex(int, int)

Computes the flat bit index for a specific choice within this template. Iterates all nodes and their choices in order to produce a deterministic index.

public int GetChoiceBitIndex(int nodeId, int choiceIndex)

Parameters

nodeId int

The node containing the choice.

choiceIndex int

The index of the choice within the node's Choices list.

Returns

int

The bit position (0–15), or -1 if not found or exceeds MaxTrackedChoices.

Remarks

-1 means "this choice cannot be tracked", and it is returned for two very different reasons: the choice does not exist, or it exists but falls past the sixteenth choice in the template and has no bit left in the short mask. Callers must treat both as a refusal. Treating -1 as "not yet taken" is what made every choice past the sixteenth infinitely repeatable — the caller skipped the already-taken test AND the bit-recording, so the choice's rewards were granted again on every click.

GetNode(int)

public DialogueNode GetNode(int nodeId)

Parameters

nodeId int

Returns

DialogueNode

GetNodeMap()

Returns the cached node map, building it on first access.

public Dictionary<int, DialogueNode> GetNodeMap()

Returns

Dictionary<int, DialogueNode>

Dictionary mapping node IDs to their DialogueNode instances.

GetTotalChoiceCount()

Counts every authored choice across every node, using the same enumeration order GetChoiceBitIndex(int, int) uses to assign bits.

public int GetTotalChoiceCount()

Returns

int

The total number of choices in this template.

Remarks

A template with CacheDialogueChoices enabled and more choices than MaxTrackedChoices cannot express "already taken" for the choices past the sixteenth — GetChoiceBitIndex(int, int) returns -1 for them and there is no bit to set. Every one of those choices, and the rewards its OnSelectActions grant, is then repeatable forever. The server uses this count to refuse such a template outright rather than serve a conversation whose one-time promises it cannot keep.

OnLoad(string, string, int)

Called when the dialogue template is loaded into cache. Loads the icon on the client.

public override void OnLoad(string typeName, string resourceName, int resourceID)

Parameters

typeName string
resourceName string
resourceID int

OnUnload(string, string, int)

Called when the dialogue template is unloaded from cache. Releases the icon on the client.

public override void OnUnload(string typeName, string resourceName, int resourceID)

Parameters

typeName string
resourceName string
resourceID int