Introduction to Morpheus Networking
What is Morpheus Networking?
In MSquared, we replace Unreal's standard networking with our own custom implementation, called Morpheus.
Morpheus is the technology that enables thousands of players and objects to be networked together in the same space, in real time, whilst using the bandwidth of a standard battle royale game.
The fundamental concepts of Morpheus networking are the same as in Unreal:
A single server coordinates multiple clients
The basic unit of networking is the actor
Actors are synchronised ("replicated") between server and client using two mechanisms:
Variable replication
RPCs
This document assumes a rough familiarity with these concepts, and focuses on Morpheus's essential differences from Unreal.
Morpheus Actors
In a Morpheus game, only actors that inherit from AMorpheusActor
are networked. All other actor types are local-only. If you spawn an AMorpheusActor
on the server, it will be replicated to all clients immediately. AMorpheusActors
should only be destroyed on the server, and the actor's destruction will also be replicated to all clients immediately.
Each client sees every AMorpheusActor
in the world; there is no concept of 'net relevancy' or 'checking in and out' an actor.
Replication
Network Levels
Although every client sees every AMorpheusActor
in the world, it may not hold the full state for all of them. On each client, each AMorpheusActor
is present at one of three network levels:
Background
Midground
Foreground
Only actors in the foreground are fully replicated.
For a detailed description of how network levels work, see Network Levels.
Authority
Unlike in standard Unreal, a AMorpheusActor
may have an authoritative client. This is an immutable property assigned when the actor is spawned. An actor's client authority affects both variable replication and RPCs.
(For how to assign a client authority to an actor, see "Spawning and Destroying" below.)
Variable Replication
In Morpheus, you can mark blueprint variables for replication the same way you would in Unreal. However, existing Unreal replication features such as RepNotify behave differently in Morpheus. For more information on how these features work and how to apply them in your variable definitions, see Replicated Properties.
RPCs
Morpheus supports the three main types of Unreal RPC: Server
, Client
and NetMulticast
. However, the semantics of these differ from standard Unreal networking. For further information, see RPCs.
Morpheus Actor Components
In order to be networked, a component must:
Inherit from
UMorpheusActorComponent
Belong to an
AMorpheusActor
Be created in its owning actor's constructor, using
CreateDefaultSubobject
. Components added to existing actors won't be replicated.
Authority and network level are delegated to the component's owning actor.
Variable replication and RPCs work the same way as for AMorpheusActor
.
Spawning and Destroying
Spawning an AMorpheusActor
AMorpheusActor
Only the server can spawn replicated AMorpheusActor
s. You can spawn them from server blueprints, using Unreal's standard SpawnActor
functions. In addition, Net Startup Actors that are AMorpheusActors
will be automatically spawned and replicated when their level starts up or their sublevel streams in.
By default, an AMorpheusActor
has server authority. To spawn an AMorpheusActor
with client authority, you must call SpawnMorpheusActorWithClientAuthority
on the server. You identify the authoritative client by passing in an AMorpheusClientConnection
; this is typically obtained by calling the AMorpheusActor
function ServerGetRpcCallerConnection
from within the handler for a Server
RPC.
Morpheus does not support authority transfer. If a client disconnects, the server destroys any AMorpheusActor
s which that client had authority over.
Destroying an AMorpheusActor
AMorpheusActor
Only the server can destroy replicated AMorpheusActor
s, using the standard Unreal Destroy
functions.
Lifecycle Events
For AMorpheusActor
s and UMorpheusActorComponent
s, there's a single change to the standard Unreal actor life cycle. Instead of the standard BeginPlay
event, you need to use MorpheusBeginPlay
. (BeginPlay
still exists, but shouldn't be used - it will print warnings in the blueprint compiler if you do use it.)
The call to MorpheusBeginPlay
marks the point at which networking functionality becomes available. RPCs sent from within MorpheusBeginPlay
are queued up and sent later, once the actor has completed initialization.
Last updated