Skip to content

Dialogue Manager Component

Dominik Morse edited this page Jun 11, 2024 · 8 revisions

MounteaDialogueManager Component Class Documentation

Overview

The UMounteaDialogueManager is a component class designed to manage dialogues within a game. It is intended to be attached to a Player State or any other State capable of triggering dialogues. The component implements the IMounteaDialogueManagerInterface, providing various functionalities to start, stop, and manage dialogues, including updating the UI, handling events, and maintaining dialogue context.


Properties

List of Properties

DialogueWidgetClass

The widget class used for displaying the dialogue UI. Can be configured in project settings.

Type
TSubclassOf
Limitation Explanation
SaveGame Persists between game sessions.
EditAnywhere Editable in the editor.
MustImplement Must implement MounteaDialogueWBPInterface.

DefaultManagerState

The default state of the dialogue manager, used to initialize the manager and as a fallback state once dialogue ends.

Type
EDialogueManagerState
Limitation Explanation
SaveGame Persists between game sessions.
EditAnywhere Editable in the editor.

ManagerState

The current state of the dialogue manager. Determines if the manager can start or close a dialogue.

Type
EDialogueManagerState
Limitation Explanation
ReplicatedUsing Synchronized across networked instances.
VisibleAnywhere Read-only in the editor.

DialogueWidgetPtr

A pointer to the currently active dialogue widget. Transient and used only at runtime.

Type
TObjectPtr
Limitation Explanation
Transient Not saved or loaded from disk.
VisibleAnywhere Read-only in the editor.

DialogueContext

Holds temporary data related to the current dialogue instance.

Type
TObjectPtr
Limitation Explanation
VisibleAnywhere Read-only in the editor.

ReplicatedDialogueContext

A structure for replicating the dialogue context across the network.

Type
FMounteaDialogueContextReplicatedStruct
Limitation Explanation
None None

TimerHandle_RowTimer

Manages the timer for dialogue rows, ensuring they are processed correctly.

Type
FTimerHandle
Limitation Explanation
Transient Not saved or loaded from disk.
VisibleAnywhere Read-only in the editor.

bWasCursorVisible

Saves the cursor visibility state when a dialogue starts, restoring it when the dialogue ends.

Type
uint8
Limitation Explanation
Transient Not saved or loaded from disk.
VisibleAnywhere Read-only in the editor.

DialogueContextReplicationKey

A key used to manage replication of the dialogue context.

Type
int
Limitation Explanation
Transient Not saved or loaded from disk.
VisibleAnywhere Read-only in the editor.

Events

Events are used to broadcast messages to multiple listeners. They are particularly useful in decoupling different parts of the code, allowing them to communicate without direct references to each other. In the UMounteaDialogueManager component, events are used to notify other parts of the system about changes in the dialogue state, such as when a dialogue starts, updates, or finishes. These events can be assigned and handled in Blueprints, providing flexibility for designers and developers.

List of Events

OnDialogueInitialized

Event called when the dialogue is initialized.

Type
FDialogueInitialized
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueStarted

Event called when the dialogue starts.

Type
FDialogueEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueClosed

Event called when the dialogue is closed. This can be triggered either manually or automatically.

Type
FDialogueEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueContextUpdated

Event called when the dialogue context is updated.

Type
FDialogueContextUpdated
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueUserInterfaceChanged

Event called when the dialogue widget class or widget changes.

Type
FDialogueUserInterfaceChanged
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueNodeSelected

Event called when a new dialogue node is selected.

Type
FDialogueNodeEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueNodeStarted

Event called when a dialogue node starts.

Type
FDialogueNodeEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueNodeFinished

Event called when a dialogue node finishes.

Type
FDialogueNodeEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueRowStarted

Event called when a dialogue row starts.

Type
FDialogueRowEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueRowFinished

Event called when a dialogue row finishes.

Type
FDialogueRowEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnNextDialogueRowDataRequested

Event called when the next dialogue row data update is requested. It is bound to the FinishedExecuteDialogueRow function and should be used carefully.

Type
FDialogueRowEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueFailed

Event called if the dialogue fails to execute, providing an error message explaining why.

Type
FDialogueFailed
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueManagerStateChanged

Event called when the dialogue manager state changes.

Type
FDialogueManagerStateChanged
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueVoiceStartRequest

Event called when a new voice line is requested to play in dialogue.

Type
FDialogueVoiceEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

OnDialogueVoiceSkipRequest

Event called when the user requests to skip a dialogue voice line.

Type
FDialogueVoiceEvent
Limitation Explanation
BlueprintAssignable Can be assigned in Blueprints.

Interface Inherited Functions

Interface inherited functions are methods that the UMounteaDialogueManager class must implement from the IMounteaDialogueManagerInterface. These functions provide core functionality and are called within the code to manage the dialogue system. They do not have the flexibility of being directly overridden in Blueprints, but they provide the underlying logic and mechanics for the dialogue system and can be called (mostly) from Blueprints.

List of Inherited Functions

GetDialogueWidgetClass

Returns the widget class used to display the dialogue UI.

Return
TSubclassOf
Limitation Explanation
None None

GetDialogueContext

Retrieves the current dialogue context associated with this dialogue instance.

Return
UMounteaDialogueContext*
Limitation Explanation
None None

GetDialogueManagerState

Retrieves the current dialogue manager state.

Return
EDialogueManagerState
Limitation Explanation
None None

GetDefaultDialogueManagerState

Retrieves the default dialogue manager state.

Return
EDialogueManagerState
Limitation Explanation
None None

ProcessNode

Processes the current active node.

Return
void
Limitation Explanation
None None

SetDialogueWidgetClass

Sets the widget class for the dialogue UI.

Return
void
Input Type Description
NewWidgetClass TSubclassOf The new widget class to set.
Limitation Explanation
None None

SetDialogueUIPtr

Sets the dialogue UI pointer.

Return
void
Input Type Description
DialogueUIPtr UUserWidget* UserWidget pointer to be saved as Dialogue UI.
Limitation Explanation
None None

StartExecuteDialogueRow

Starts dialogue row execution.

Return
void
Limitation Explanation
None None

FinishedExecuteDialogueRow

Handles cleanup once a dialogue row is finished.

Return
void
Limitation Explanation
None None

NextDialogueRowDataRequested

Handles the request for the next dialogue row data update.

Return
void
Input Type Description
Context UMounteaDialogueContext* The dialogue context.
Limitation Explanation
None None

SetDialogueContext

Sets the new dialogue context.

Return
void
Input Type Description
NewContext UMounteaDialogueContext* The dialogue context to be set.
Limitation Explanation
None None

SetDialogueManagerState

Sets the dialogue manager state.

Return
void
Input Type Description
NewState EDialogueManagerState The manager state to be set.
Limitation Explanation
None None

SetDefaultDialogueManagerState

Sets the default dialogue manager state.

Return
void
Input Type Description
NewState EDialogueManagerState The default manager state to be set.
Limitation Explanation
None None

Interface Inherited Blueprint Events

Blueprint events are functions that can be overridden in Blueprints to customize the behavior of the dialogue system. These events are callable and implementable in Blueprints, allowing game designers to easily modify and extend the functionality without needing to alter the underlying C++ code. They provide flexibility and ease of use for non-programmers working within the Unreal Engine Editor. Those functions provide C++ logic that can be used (using Call Parent logic in Blueprint) or ignored (by not calling Parent).

List of Inherited Blueprint Events

CallDialogueNodeSelected_Implementation

Notifies the dialogue that a node has been selected.

Return
void
Input Type Description
NodeGUID FGuid The GUID of the selected node.
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="select, chosen, option") Provides additional metadata for the Blueprint editor.

GetOwningActor_Implementation

Returns the owning actor for this dialogue manager component.

Return
AActor*
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.

PrepareNode_Implementation

Prepares the node for execution by processing all decorators.

Return
void
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.

InitializeDialogue_Implementation

Initializes the dialogue with the provided participants.

Return
void
Input Type Description
OwningPlayerState APlayerState* The player state owning the dialogue.
Participants FDialogueParticipants The participants involved in the dialogue.
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="UI, Widget") Provides additional metadata for the Blueprint editor.

StartDialogue_Implementation

Starts the dialogue if possible.

Return
void
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="show, widget") Provides additional metadata for the Blueprint editor.

CloseDialogue_Implementation

Closes the dialogue if it is active.

Return
void
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="show, widget") Provides additional metadata for the Blueprint editor.

InvokeDialogueUI_Implementation

Attempts to display the dialogue UI. If it fails, it provides an error message explaining what went wrong.

Return
bool
Input Type Description
Message FString& The error message explaining why the UI cannot be added to the screen.
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="show, widget") Provides additional metadata for the Blueprint editor.

UpdateDialogueUI_Implementation

Attempts to update the dialogue UI based on the provided command. If it fails, it provides an error message explaining what went wrong.

Return
bool
Input Type Description
Message FString& The error message explaining why the UI cannot be updated.
Command FString& The command to be processed.
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="show, widget") Provides additional metadata for the Blueprint editor.

CloseDialogueUI_Implementation

Attempts to close the dialogue UI.

Return
bool
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="close, exit, stop, widget") Provides additional metadata for the Blueprint editor.

GetDialogueWidget_Implementation

Returns the widget used to display the current dialogue.

Return
UUserWidget*
Limitation Explanation
BlueprintNativeEvent Can be overridden in Blueprints.
BlueprintCallable Can be called from Blueprints.
meta=(Keywords="UI, Widget") Provides additional metadata for the Blueprint editor.

Dialogue Manager Flow

A simplified graph showcasing how the Dialogue Manager process Dialogue Logic.

graph TD

subgraph Binding
        A[InitializeBindings] --> B[OnDialogueInitializedEvent_Internal]
        A --> C[OnDialogueContextUpdatedEvent_Internal]
        A --> D[OnDialogueUserInterfaceChangedEvent_Internal]
        A --> E[OnDialogueStartedEvent_Internal]
        A --> F[OnDialogueClosedEvent_Internal]
        A --> G[OnDialogueNodeSelectedEvent_Internal]
        A --> H[OnDialogueNodeStartedEvent_Internal]
        A --> I[OnDialogueNodeFinishedEvent_Internal]
        A --> J[OnDialogueRowStartedEvent_Internal]
        A --> K[OnDialogueRowFinishedEvent_Internal]
        A --> L[OnDialogueVoiceStartRequestEvent_Internal]
        A --> M[OnDialogueVoiceSkipRequestEvent_Internal] 
    end

Loading
graph TD
    
    subgraph Begin_Play
        BeginPlay --> InitializeBindings
        BeginPlay --> SetDialogueManagerState
    end

    subgraph Processing_Node
        ProcessNode --> PrepareNode

        PrepareNode --> StartExecuteDialogueRow
    end

    subgraph Dialogue_Node_Execution
        StartExecuteDialogueRow --> FinishedExecuteDialogueRow
        StartExecuteDialogueRow -.->|Update Dialogue Row UI| UpdateDialogueUI        
        
        CallDialogueNodeSelected --> SetDialogueContext
        CallDialogueNodeSelected --> OnDialogueNodeSelectedEvent_Internal

        SetDialogueContext --> NetPushDialogueContext

        subgraph Dialogue_Rows_Execution
            OnDialogueNodeFinishedEvent_Internal --> Decide_HasOtherNodes{Is Last Node?}
            Decide_HasOtherNodes -->|No| Decide_DoesNextAutoStart{Does Next Node Auto Start?}
            Decide_HasOtherNodes -->|Yes| OnDialogueClosed

            Decide_DoesNextAutoStart -.->|Yes - Show Selectable Options| UpdateDialogueUI --> CallDialogueNodeSelected
            Decide_DoesNextAutoStart -->|No| UpdateDialogueUI

            FinishedExecuteDialogueRow --> Decide_FinishedAuthority{Has Authority?}
            Decide_FinishedAuthority --> |No| FinishedExecuteDialogueRow_Server
            Decide_FinishedAuthority --> |Yes| Decide_LastRow{Is last Row?}
            FinishedExecuteDialogueRow_Server --> Decide_LastRow{Is last Row?}

            Decide_LastRow -->|No| NextDialogueRowDataRequested
            Decide_LastRow -->|Yes| OnDialogueNodeFinishedEvent_Internal
            NextDialogueRowDataRequested --> StartExecuteDialogueRow
        end
    end
     
    subgraph Closed_Dialogue
        OnDialogueClosed --> OnDialogueClosedEvent_Internal
        OnDialogueClosedEvent_Internal -.-> CloseDialogueUI
        OnDialogueNodeSelectedEvent_Internal --> StartExecuteDialogueRow
        OnDialogueNodeStartedEvent_Internal --> ProcessNode
    end

    subgraph Delegates_Node_Selected
        OnDialogueNodeSelectedEvent_Internal --> NetPushDialogueContext
        OnDialogueNodeSelectedEvent_Internal --> UpdateDialogueUI
        OnDialogueNodeSelectedEvent_Internal --> PrepareNode    
    end

    subgraph Delegates_Initialize        
        OnDialogueInitializedEvent_Internal --> OnDialogueContextUpdatedEvent_Internal
        OnDialogueInitializedEvent_Internal --> OnDialogueStartedEvent_Internal
    end

    subgraph Delegates_Flow
        OnDialogueContextUpdatedEvent_Internal --> SetDialogueContext
        OnDialogueUserInterfaceChangedEvent_Internal --> OnDialogueUserInterfaceChangedEvent        
        OnDialogueNodeStartedEvent_Internal --> StartExecuteDialogueRow
        OnDialogueNodeFinishedEvent_Internal --> OnDialogueClosed
        OnDialogueRowStartedEvent_Internal --> OnDialogueVoiceStartRequest
        OnDialogueRowFinishedEvent_Internal --> OnDialogueRowFinished
        OnDialogueVoiceStartRequestEvent_Internal --> PlayParticipantVoice
        OnDialogueVoiceSkipRequestEvent_Internal --> SkipParticipantVoice
    end

    subgraph Main_Flow
        InitializeDialogue --> InitDialogueCheck{Has Authority}
        InitDialogueCheck --> |Yes| StartDialogue
        InitDialogueCheck --> |No| InitializeDialogue_Server
        InitializeDialogue_Server --> StartDialogue
        SetDialogueContext --> SetDialogueContext_Server

        subgraph Starting_Dialogue
            StartDialogue --> StartDialogueCheck{Has Authority}
            StartDialogueCheck --> |Yes| SetDialogueManagerState
            StartDialogueCheck --> |No| StartDialogue_Server
            StartDialogue_Server --> SetDialogueManagerState
            StartDialogue -.-> InvokeDialogueUI
            StartDialogue --> ProcessNode
            StartDialogue --> OnDialogueStartedEvent_Internal
        end

        subgraph Closing_Dialogue
            CloseDialogue --> CloseDialogueCheck{Has Authority}
            CloseDialogue --> CloseDialogueUI
            CloseDialogueCheck --> |Yes| SetDialogueManagerState
            CloseDialogueCheck --> |No| CloseDialogue_Server
            CloseDialogue_Server --> SetDialogueManagerState
            CloseDialogue --> OnDialogueClosedEvent_Internal
        end
        
        subgraph Processsing_UI
            InvokeDialogueUI --> InvokeDialogueUI_Client
            UpdateDialogueUI --> UpdateDialogueUI_Client
            CloseDialogueUI --> CloseDialogueUI_Client            
            SetDialogueWidgetClass --> SetDialogueWidgetClass_Server            

            InvokeDialogueUI_Client --> UpdateDialogueUI
            CloseDialogueUI_Client --> UpdateDialogueUI
            UpdateDialogueUI -->|string_command| ProcessDialogueUI
        end
    end
Loading
Clone this wiki locally