🌐Replication

Replication is the Unreal term for how data is networked between server and client(s).

In Origin, we replace Unreal networking with our own customer implementation called Morpheus.

You don't need to understand everything to do with Morpheus to get started.

What is Morpheus?

Morpheus is the technology that enables thousands of players and objects to be in the same space. It contains three parts:

  • Morpheus Networking - Allowing for thousands of players and objects to be networked with each other, with real-time characteristics, whilst using the bandwidth of a standard battle royale game.

  • Morpheus Rendering - Allowing for thousands of individually animated, fully customised 3d avatars to be rendered on-screen at the same time.

  • Morpheus Crowd Audio - Realistic spatial audio experience for thousands of players.

Actor Replication

In a Morpheus game, any AMorpheusActor (or actor derived from AMorpheusActor) is replicated to all clients, and no other actor types are. If you spawn an AMorpheusActor on the server, this 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. So if there is no filtering, how do we process all of these actors being replicated to our clients? How do we avoid bottlenecks on our server for the massive scale we're trying to achieve? These questions can be answered with a number of new concepts introduced with the Morpheus Plugin. Below are details on each new concept, how they work and how they are applied.

Network Levels

Although every client sees every AMorpheusActor in the world, each AMorpheusActor is visible at one of three network levels:

  • Background

  • Midground

  • Foreground

For a detailed breakdown of network levels, please see the Network Levels page.

Properties

Network Levels are applied at a property level, along with other new concepts such as Client Authority. Existing Unreal property specifier functionality such as RepNotify behave slightly differently in Morpheus. For more information on how these features work and how to apply them in your property definitions, visit the Morpheus Actor Properties page.

RPCs

Morpheus supports the three main types of RPC: Server, Client and NetMulticast. However, the semantics of these differ from standard Unreal networking. For further information, see the Morpheus RPCs page.

Morpheus Actor Components

Components derived from UMorpheusActorComponent are able to replicate in Morpheus, while all other components are not. All the same rules apply as for AMorpheusActor outlined above.

If the owning actor is authoritative, all its components are authoritative as well.

In addition, UMorpheusActorComponents must always be created in their owning actor's constructor using CreateDefaultSubobject. Components added at runtime won't be replicated.

You can also use AMorpheusActor::LateSpawnComponents to create a UMorpheusActorComponent. This is the latest point in the actor’s lifecycle where creating a component is allowed. This is useful if you know you’re going to have a certain type of component but the concrete subtype depends on a default property set on the actor. In this case you can’t create the component in the constructor because properties won’t have been loaded yet.

Spawning and Destroying

Spawning

Only the server can spawn replicated AMorpheusActors. The server can spawn AMorpheusActor using Unreal's standard UWorld::SpawnActor methods. Net Startup Actors (actors placed in a level or sublevel) that are AMorpheusActors will also be automatically replicated. Net Startup Actors are spawned by Unreal when a level starts up or when the sublevel containing them streams in. The UMorpheusServerView listens for level streaming events to identify and begin replicating any newly spawned Net Startup Actors.

To spawn an AMorpheusActor with client authority, the server can call UMorpheusBlueprintFunctionLib::SpawnMorpheusActorWithClientAuthority or SpawnMorpheusActorWithClientAuthority in blueprints. These methods identify a client with a AMorpheusClientConnection* ClientConnection, which is typically obtained from AMorpheusConnection* AMorpheusActor::ServerGetTrustedRpcCallerConnection() during the handler of a Server RPC.

Morpheus does not support authority transfer. Morpheus Actors can be created "with client authority", meaning one client connection is authoritative for its replication. If a client disconnects, the server destroys any Morpheus Actors that were created with client authority for that client.

Destroying an AMorpheusActor

Only the server can destroy replicated AMorpheusActors, using the standard Unreal Destroy methods.

Lifecycle events

Blueprint

In Blueprint, there's a new lifecycle event MorpheusBeginPlay for blueprints extending AMorpheusActor and UMorpheusActorComponent. The default BeginPlay event still exists, but shouldn't be used (it will print warnings in the blueprint compiler if you do use it).

When MorpheusBeginPlay is called, you have access to all networking functionality on both AMorpheusActors and UMorpheusActorComponents. RPCs sent from within MorpheusBeginPlay are queued up and sent later once the actor has fully started to replicate.

See also

Mark, components and replication

Last updated