Quick Start Guide
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.
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:
- If it doesn't already exist, create a
Pluginsfolder inside your Unreal project folder. - Download the Fusion Unreal Plugin.
- Unzip the Fusion Unreal Plugin and copy the
PhotonFusionfolder into thePluginsfolder. - Open the project and ensure the
Photon Fusionplugin is enabled in the Plugin window. - Open the
Fusion Settingssection 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.
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 a Fusion Actor Settings component. It has a number of properties that can be adjusted to better suit your game, however we find the defaults generally perform well for a range of common scenarios.
In this guide the third person character will be replicated.
Open up BP_ThirdPersonCharacter and add the Fusion Actor Setting component. You do not need to adjust any of the properties at this stage.
Testing
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 Processoption:- 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
If you press the space bar to jump or walk off a ledge you will see that the falling animation does not play for other clients viewing your character.
Future versions of Photon Fusion for Unreal will provide improved support for the Character Movement Component and the Mover Component so that this issue does not need to be manually fixed. However this guide will go through the process of fixing it in order to demonstrate Fusion's support for replicating properties.
Add the following logic to BP_ThirdPersonCharacter to save the EMovementMode state as a replicated variable. Name the variable CurrentMovementMode and set the replication setting to RepNotifiy
Add the following logic to the RepNotifiy function. The movement mode is set to match the replicated variable.
The movement mode for each character should now be replicated.
Try jumping or walk off a ledge and you should see the falling animation play for all 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.
- Create a new StaticMesh BP Actor called
BP_Ball. - Set the mesh to be a ball and ensure the
Simuate Physicsoption is enabled. - Add the
Fusion Actor Settingscomponent. - Adjust the
Auto Dynamic Ownership Rangeon theFusion Actor Settingscomponent to be 500. - Drag the
BP_Ballinto 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.
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.
- Add the
StarterContentpack 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
- Open
BP_ThirdPersonCharacter. - Create a new
Custom EventcalledSpawnExplosionRPCwith a Vector input parameter for the location. Add the logic from the image below. - Right click on the event graph and create a
Custom Fusion RPC. - In the details panel for the
Custom Fusion RPCselect theSpawnExplosionRPCevent from theReference Event Namedrop down. - Hook the
Custom Fusion RPCnode up to theEkeyboard event.
When playing the game you should see an explosion effect appear whenever the E key is pressed.