Documentation Home
v1.22 v1.23
v1.22 v1.23

RPC

RPC

In a collaborative session, one Skyreal VR instance is the server and the others are clients. To make your extension work in collaboration, keep three rules in mind:

  • The server holds the truth. Replicated data only goes from the server to the clients.

  • A client can only send requests (RPC) to the server, through an object it owns.

  • A client cannot spawn a replicated actor itself, nor get a return value from a request.

This page shows how to apply them in Blueprint. For the full picture, see the Unreal Engine networking overview.

Which objects exist where

Class

How many

On the server

On the clients

Game Instance

One per application

Not replicated

Not replicated

Game Mode

One per map

Yes

No

Game State

One per map

Yes

Yes

Player Controller

One per user

Yes, all of them

Only the local user's

Pawn

One per user

Yes

Yes, all of them

For example, every pawn exists on every instance: this is why you see the other users' avatars. A Player Controller represents a user's behavior, so the other users never see it.

Replicate data from the server to the clients

  1. In your actor's Class Defaults, tick Replicates. The actor now appears on every client.

  2. To sync its position and rotation, also tick Replicate Movement. Only moves made on the server are replicated.

Replicates and Replicate Movement in Class Defaults
  1. For each variable to sync, set Replication in its Details panel:

    • Replicated: the value is synced, nothing else happens.

    • RepNotify: the value is synced, then an OnRep_ function runs on each client. Use it to react to the change.

Replication setting of a variable

Example: Unreal does not replicate an actor's visibility. To sync it, the actor holds a TestVar variable set to RepNotify. When the server changes it, OnRep_TestVar runs on each client and applies the visibility locally.

OnRep function applying the visibility

Send a request to the server (RPC)

A client can only call the server through an object it owns, such as its Player Controller. Skyreal VR gives each user an RPC component for this: you declare it once, and Skyreal creates it for every user with the right ownership.

RPC round trip

1. Declare your RPC component

  1. In your extension's RegistrableAssets folder, create a data asset of type SkrRPCInterfaceComponentDescription.

Create the RPC component description
  1. Next to Component Class To Spawn, click + to create a Blueprint of type SkrRPCInterfaceComponent. Save it outside RegistrableAssets: only data assets go there.

Create the RPC component Blueprint

2. Add a server event

  1. Open the component and add a Custom Event, for example Server_EditObjectVisibility.

Add a custom event
  1. In its Details panel, set Replicates to Run on Server.

Set the event to Run on Server
  1. Write what the server must do. Here, the event sets the TestVar RepNotify variable of the target actor.

Server event setting the RepNotify variable

3. Call it from anywhere

From any Blueprint, on any instance:

  1. Call Get Rpc Dispatcher with Looked Player Controller = Get Player Controller (index 0) and Rpc Class = your component.

  2. Cast the result to your component.

  3. Call your server event.

Call the server event through Get Rpc Dispatcher

The visibility can now be changed from any instance, and it is synced to everyone. Get Rpc Dispatcher returns the first component of the requested class: give each RPC component its own class.

Spawn an actor from a client

A client cannot spawn a replicated actor itself, and a request cannot return the spawned actor. Skyreal VR provides SkrActorSpawnerRPCDispatcher for this:

  1. Call Get Rpc Dispatcher with Rpc Class = SkrActorSpawnerRPCDispatcher, and cast the result.

  2. Call Spawn Actor On Server Async Latent with the actor class and its transform.

  3. The node is latent: it waits, without blocking the game, until the server has spawned the actor. Then its output gives you the actor.

Leave Actor Registration Rule on Register. It only matters for Skyreal actors such as manikins, measures or physics objects, so that they behave like the ones Skyreal creates. It has no effect on an actor whose parent class is Actor.