Quick Start Guide

Preview

The Fusion Unreal SDK 3.0.0 is provided as development snapshots and is not intended to be used for live or released games. There may be blocker bugs and the API can change or break during the preview phase.

Introduction

This document is a quick reference to start developing using Fusion with Unreal. The guide will explain the process of adding networked movement to a third person game and demonstrate a few core features of Photon Fusion for Unreal.

This guide builds upon a template from Unreal 5.6. However the approach and methods used can be applied to all Unreal versions supported by Photon Fusion.

Characters in a networked version of the Third Person template

Create a new project

Create a new Unreal project in Unreal 5.6 and select the Third Person template as a base.

Setup the Photon Fusion Plugin

To setup Fusion Unreal in a new or existing project:

  1. If it doesn't already exist, create a Plugins folder inside your Unreal project folder.
  2. Download the Fusion Unreal Plugin.
  3. Unzip the Fusion Unreal Plugin and copy the PhotonFusion folder into the Plugins folder.
  4. Open the project and ensure the Photon Fusion plugin is enabled in the Plugin window.
  5. Open the Fusion Settings section of the project settings and fill in your App ID.

Connecting to Photon and Joining a Room

The first thing the game needs to do is join a Photon room. The Fusion Online Subsystem can be used to connect to Photon and then to create or join a room. Once in a room, states between clients can be replicated.

Create a new Actor Blueprint called BP_FusionSetup and add the following BP logic to the BeginPlay of the Event Graph.

BP logic for connecting to Photon and joining a room

Any string can be used for the Room Name and set an appropriate Region (currently available: eu, us, asia).

Finally, add BP_FusionSetup anywhere in the Lvl_ThirdPerson map in order for the logic to join the room to be executed as soon as the game starts.

Actor Replication

In order for an Actor to be considered for replication it needs to have Replicates ticked and have a Fusion Actor Settings component.

Fusion Actor Settings has a number of properties that can be adjusted to better suit your game, however we find the majority of the defaults perform well for a range of common scenarios.

One property to be aware of is Disable Interpolation. By default properties replicated by Fusion will interpolate between the current local value and the new value that has been replicated. This default behaviour can reduce stutters in movement of objects when the owner sets the position of the actor directly. However, In some situations it is best to disable this default behaviour by ticking the Disable Interpolation box because logic outside of Fusion already handles the smoothing.

In this guide the third person character will be replicated, as Fusion has support for the Character Movement Component which provides smoothing, the Disable Interpolation box should be ticked.

  • Open up BP_ThirdPersonCharacter and add the Fusion Actor Settings component.
  • Tick Disable Interpolation in the details of the Fusion Actor Settings component.
  • Ensure Replicates is ticked in the Class Defaults.

Testing

Important

Make sure each PIE window will be run in its own process by disabling the Run Under One Process option in Editor Preferences.

Enough setup has now been performed to allow for basic character replicated movement. There are however some editor settings that need to be adjusted to allow for testing with multiple PIE clients.

  • Make sure each PIE window will be run in its own process by disabling the Run Under One Process option:

    • Editor Preferences -> Level Editor -> Play -> Multiplayer Options -> Run Under One Process
  • While not a necessity, we recommend disabling the option to Use Less CPU when in Background

    • Editor Preferences -> General -> Performance -> Editor Performance -> Use Less CPU when in Background

Open the Lvl_ThirdPerson map and start the game with multiple PIE windows.

After you press play you should see all your characters standing in the map. Take a moment to switch between windows and run around as the different players. You should see each character move around from all client perspectives.

Congratulations, you have just created your first networked experience using Photon Fusion!

Property Replication

This section takes advantage of Photon Fusion's support for standard Unreal replication by adding the ability to change the color of the player character and have that change appear on all clients.

Add the following logic to BP_ThirdPersonCharacter to randomly create and save a new color for the character when the P key is pressed. Name the Linear color variable Paint Tint and set the replication setting to RepNotify

BP logic for setting the PaintTint

Add the following logic to the RepNotify function. The Paint Tint variable is used to set the corresponding parameter in the material. (For simplicity sake we create the Dynamic Material here, but it is generally best practice to cache it).

PaintTint On Rep BP logic

The player colour change should now be replicated for each player.

Only one variable type has been replicated here, but Photon Fusion has support for all variable types either with or without a RepNotify.

Try pressing the P key in game to see a new color randomly chosen for your character. The color change will be replicated to the other clients.

Adding a Physics Object

Photon Fusion offers Forecast mode for synchronising physics object states between clients. Extrapolation is used to predict the remote state of the object before combining it with the local state and physics simulation.

Any Actor with a StaticMesh as the root scene object and Simulate Physics enabled will use Forecast by default. This can be disabled in the Fusion Actor Settings component as required, in which case standard interpolation, if enabled, will be used instead.

  1. Create a new StaticMesh BP Actor called BP_Ball.
  2. Ensure replication is enabled by ticking Replicates on the actor.
  3. Set the mesh to be a Sphere and ensure the Simuate Physics option is enabled.
  4. Add the Fusion Actor Settings component.
  5. Adjust the Auto Dynamic Ownership Range on the Fusion Actor Settings component to be 500.
  6. Drag the BP_Ball into the map.

Auto Dynamic Ownership Range is used to automatically adjust ownership of the actor based on player distance. This means that a player within this range will be assigned ownership of the BP_Ball and will become the remote state for the other clients to base their extrapolation on.

This ranged based check can be disabled by setting the value to 0 and then manually calling SetsWantsOwner() on the FusionOnlineSubsystem as required.

Players interacting with the physics based object

RPCs

Photon Fusion has support for custom Fusion RPCS. In the steps below we will create an RPC to spawn an explosion effect at the players feet whenever the E key is pressed.

  1. Add the StarterContent pack to the project if it has not yet been imported. This will make an explosion effect available for use.
    • From the Content panel: Add -> Add Feature or Content Pack -> Content -> Starter Content
  2. Open BP_ThirdPersonCharacter.
  3. Create a new Custom Event called SpawnExplosionRPC with a Vector input parameter for the location. Add the logic from the image below.
  4. Right click on the event graph and create a Custom Fusion RPC.
  5. In the details panel for the Custom Fusion RPC select the SpawnExplosionRPC event from the Reference Event Name drop down.
  6. Hook the Custom Fusion RPC node up to the E keyboard event.
RPC BP logic

When playing the game you should see an explosion effect appear whenever the E key is pressed.

Players triggering the explosion RPC
Back to top