Multiplayer
Table of Contents
- Overview
UPulseQuestManager– Owner Only ReplicationAPulseSharedQuestHost– Shared Quests- Objective Net Modes
- Authority Helpers
- Replication Events on Clients
- Recommended Pattern
Overview
Quests run on the authority. Clients get the quest manager data, the quest data of running quests and objectives with ServerAndClient net mode as replicated sub-objects, and the results of finished quests and objectives by reliable RPC.
Authority only (refused with a warning on clients): StartQuest, StopQuest, SendEventToQuest, StartObjective, CompleteObjective, progress and text changes of objectives, story flags, tracked quest, reset, save and load. The director and quest instances exist only on the authority.
UPulseQuestManager – Owner Only Replication
- The component replicates by default (Component Replicates).
- Manager data, quest data and objectives replicate to the owning connection only (put the component on the player controller or player state).
IsLocallyControlledis true on the owning client (and the listen server host for its own player).
APulseSharedQuestHost – Shared Quests
A placeable actor for quests of a group of players.
| Function | Description |
|---|---|
AddPlayer(Player) | Authority only. Player implements IPulseSharedQuestPlayerInterface (GetQuestPlayerState) |
RemovePlayer(Player) | Authority only |
bRemovePlayersOnDestroy | Default true: a player is removed automatically when its player state or player actor is destroyed (e.g. on logout) |
HasPlayer / HasPlayerState / GetAllPlayers / GetAllPlayerStates | Queries |
GetSharedQuestManagerData() | UPulseSharedQuestManagerData of the host |
The host is only net relevant for its players. OnAddedToQuestManager / OnRemovedFromQuestManager of the player interface are called when a player joins or leaves (on clients only if the player actor is replicated). With Pulse Online, PulseQuestOnlineBridge keeps one host per party and moves players with their party.
Blueprint: Shared quest for a party
- Place a
Pulse Shared Quest Host(orPulse Save Shared Quest Host) in the level and set its quest set. - On the server: for each party member →
Add Player(New Player = an actor that implementsPulse Shared Quest Player Interface, e.g. the player state). Start Queston the host. The quest replicates only to its players.Remove Playerwhen a player leaves the party. Players whose player state is destroyed (logout) are removed automatically (Remove Players On Destroy).
Objective Net Modes
EPulseObjectiveNetMode | Behavior |
|---|---|
ServerAndClient | Replicated; can call RPCs through the actor of its manager |
ServerOnly | Only on the authority |
Authority Helpers
UPulseQuestUtils:Is Authority Quest Manager,Is Local Quest Manager.- Objective:
Has Authority,Is Locally Controlled. - Quest data:
Is Client Data.
Replication Events on Clients
Clients apply replicated changes through the event queue (SyncReplicated), so the same manager events fire on clients: On Quest Started, On Quest Finished, On Objective Started, On Objective Finished, and the view models update.
- Each run of a quest has a run id, objectives carry the run id of their quest. A client adds a run when it is replicated and finishes and removes it when it is not replicated anymore (finished, reset, removed). A restart of the same quest is a new run.
- What a client knows is a ledger by run id and objective handle (
FPulseQuestClientLedger, Pulse Debugger section “Client sync”), never by object pointer: an item whose object is not resolved yet waits, and an active run or objective whose object is unresolved for a moment stays (it is not finished and added again). - A result RPC that arrives before its quest or objective is applied when the quest or objective arrives. Results that can never be applied are dropped: a result of a run or objective that already left replication, of a quest that the client does not know, of an objective whose run ended, or of a run or objective that started and finished in one tick on the server (the RPC says so,
bNeverReplicated). Pending results age and are limited. - A server reset reaches clients: their quests end with
Stoppedand are removed.
Quests on clients
The server decided which quests run, so a client resolves the replicated tag through the quest catalog without its quest set. A quest that still loads on the client (an asynchronous catalog) lets its run wait: nothing is ignored, a result that arrived waits too, and the run is added in the sync after the quest arrived, with the same events as any other run. A quest no catalog of the client knows is ignored with an error in the log: register quests made at runtime on every machine. A client that registers the quest later (its own backend answered after the run arrived) gets the run then: the change of the definitions syncs again. A load that failed for a while (timeout) lets the run wait and is asked again in the next sync.
- The run state of a quest (tag, run id, flags, owner) replicates in the quest list of the manager. A client sets it on the quest data before
On Quest Started, so listeners already see the flags and the owner. - The state of an objective (progress, text, targets) replicates in the objective list of the manager, not as properties of the objective object. Clients merge it in the sync and fire
OnProgressChanged/OnDisplayChangedfor the parts that changed, one frame after the replication, in one order with the add and finish events. - The shared host sends an update right away when the progress or text of an objective changes.
Recommended Pattern
- Quest logic in the quest StateTree (authority).
- Progress in objectives with
SaveGamevariables; UI through the view models on the owning client. - Local feedback (widgets, sounds) in objective events guarded with
Is Locally Controlled. - Party quests in an
APulseSharedQuestHost, players added on the server (they leave automatically on logout).