Unreal Engine 4 Genvid Client/Server

Adapt your code

To follow the Genvid SDK architecture you need to use two classes based on:

  • APlayerController
  • AGameState

These two classes will help you integrate the Client/Server architecture.

How it works

The client-owned PlayerController sends a Remote Procedure Call (RPC) to the server with authority (through the GenvidEvents and GenvidCommands Components).

The server receives the RPC and triggers the corresponding custom event. Then it sends an RPC to all connected clients from the GameState class (Multicast).

../../_images/GenvidModule_ClientServerSmall.png

Fig. 21 Genvid Module Client/Server

Client side

To allow an owner without authority (client) to send an RPC to the server, use a PlayerController-based class provided by Unreal Engine 4.

This is the only place where an RPC can be made from the client to the server.

You need to add your Genvid Streams/Events/Commands to your PlayerController-class, as described in the Instantiation section.

Note

Don’t forget to check the Replicated checkbox to enable the Client/Server flow. See Genvid Event Parameters.

Server side

To allow an owner with authority (server) to send an RPC to all connected clients, use the GameState-based class provided by Unreal Engine 4.

This is one place where an RPC can be made from the server to a client.

To make send an RPC from the server:

  1. In your GameState class, create a custom event for each GenvidEvent and GenvidCommand in your GenvidEvents and GenvidCommands.

    Note

    Take care of the custom event parameters signature. GameState should have the same than those created in GenvidEvents and GenvidCommands

  2. Set the replicate mode to Multicast and Reliable.

    With these settings, the server will send an RPC to all connected clients.

    ../../_images/GameState_CustomEventMulticast.png

    Fig. 22 GameState - Custom Event (Multicast)

  3. At this stage, you’re always in the GameState but on the client side. You can now call your code.

  4. To complete the loop, call the GameState custom-event from the GenvidEvents or GenvidCommands components attached to the PlayerController.

    ../../_images/GenvidEvents_CallGameStateEvent.png

    Fig. 23 PlayerController - Genvid Event (Run on Server)