0% found this document useful (0 votes)
10 views

Unity Network (Photon Engine)

The document provides an introduction to networking in Unity using Photon, focusing on popular frameworks like Photon Fusion and Photon Unity Networking (PUN2). It outlines common networking concepts, setup instructions for Fusion Host Mode, and local multiplayer testing with ParrelSync. Additionally, it introduces MercuryMessaging as a communication toolkit for modular UI components in Unity.

Uploaded by

calvin wong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Unity Network (Photon Engine)

The document provides an introduction to networking in Unity using Photon, focusing on popular frameworks like Photon Fusion and Photon Unity Networking (PUN2). It outlines common networking concepts, setup instructions for Fusion Host Mode, and local multiplayer testing with ParrelSync. Additionally, it introduces MercuryMessaging as a communication toolkit for modular UI components in Unity.

Uploaded by

calvin wong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to

Networking in
Unity with Photon
CARMINE ELVEZIO, BEN YANG
PROF. STEVE FEINER
COMS W4172
March 21, 2024

Popular Unity Networking Frameworks


► High-Level Frameworks
► P2P Style
► Photon Fusion ← We will focus on this today!
► Photon Unity Networking (PUN/PUN2)
► Self-Hosted/Dedicated Server
►MLAPI (acquired by Unity)
►Mirror
Both MLAPI and Mirror are based on Unity's deprecated UNet
►Photon Bolt
►Forge Networking Remastered
► Low-Level Framework
► DarkRift 2

More details can be found here:


https://blog.unity.com/technology/choosing-the-right-netcode-for-your-game 2

Feiner, COMS W4172, Spring 2024


Common Concepts in Networking Frameworks
► Clients connect to a listening server
► Single server—multiple clients
► Unity applications can be configured as server, client, or both

► Networked Game Object


► Similar to a regular game object, except it will automatically
sync over the network
► Players can be configured to have local authority

► Synchronized Variable/State
► Similar to a regular variable, except it will automatically sync
over the network

► Messaging/RPC (Remote Procedure Call)


► Similar to a regular method, except it can be invoked over
the network
3

Photon Unity Networking—PUN2


► One of the most popular
networking solutions for
Unity
► Beginner friendly!
► Free for up to 20 concurrent
connected users (CCU)
► Cross-platform
► Built-in matchmaking
services https://www.photonengine.com/pun

► Suitable for game with 2–8


players per room/session
► Highly scalable ($$)
4

Feiner, COMS W4172, Spring 2024


Photon Unity Networking—PUN2
► PUN2 built on
► High-level API
► Low-level Networking calls
► Platform-native DLLs
► Supports
► Networked objects in
scenes
► RPC and direct message
passing
► Custom messages

Note: PUN2 doesn't support custom server-side


logic. But we can use master client (aka host) to
achieve similar results.
5

Feiner, COMS W4172, Spring 2024


7

Fusion Host Mode: Getting Started


► Register at
www.photonengine.com
► Create a Photon Fusion
app and note its AppID
► Install 2022.3 LTS or above
► Asset Serialization
► Mono Cecil Package
► Generates low-level
netcode and injects into
C# DLL
► com.unity.nuget.mono-
[email protected]
8

Feiner, COMS W4172, Spring 2024


Fusion Host Mode: Setup

► Add that
AppID to the
Fusion Setup
Wizard

Fusion Host Mode: Scene Initialization


► Goals:
► Create a Fusion
Runner to
start/join
matches
► Create a
movable
character
► Add required
methods stubs
► Ensure you add
“using
Fusion.Sockets”! 10

Feiner, COMS W4172, Spring 2024


Fusion Host Mode: Scene Initialization

► Create the
StartGame method
► Creates the Fusion
NetworkRunner
► Gets the active scene
► Adds the
NetworkSceneManager

11

Fusion Host Mode: Scene Initialization

► Create a GUI
Button when
spawning the
game

12

Feiner, COMS W4172, Spring 2024


Fusion Host Mode:
Scene Initialization
► Create a player
avatar by adding
a NetworkObject
component
► Add a
NetworkCharacter
ControllerPrototype
► Change the
Interpolation Target

13

Fusion Host Mode:


Scene Initialization
► Spawn the player
character in
hosted mode by
replacing the
OnPlayerLeft and
OnPlayerJoined
stubs
► This is the same as
the regular Unity
Instantiate
(runner.spawn())
14

Feiner, COMS W4172, Spring 2024


Fusion Host Mode:
Scene Initialization
► Collect direction
input from the user
► Replace the
OnInput() stub with
arrow key presses

15

Fusion Host Mode:


Scene Initialization
► Apply the collected
input data to the
player avatar
► Add the Player script
to the PlayerPrefab
► Implement
FixedUpdateNetwork

16

Feiner, COMS W4172, Spring 2024


Fusion Host Mode:
Scene Initialization
► Last step!
► Create a floor for
testing
► Start multiple
instances of the
built application
► One will press Host,
the other will press
Join

17

Fusion: Next Steps


► Prediction
► Physics
► Property Changes
► RPCs
► Shared Mode
Basics
► Sample Scenes
► Asteroids Simple
► Asteroids
Advanced
► DragonHunters VR

18

Feiner, COMS W4172, Spring 2024


Local Multiplayer Testing—ParrelSync
► The workflow recommended by
Unity for local iteration

► Test multiplayer gameplay without


building by having another Unity
editor opened and mirror the
changes from the original project

https://docs-multiplayer.unity3d.com/netcode/current/tutorials/testing/testing_locally/index.html#parrelsync

Download the source code from


GitHub - VeriorPies/ParrelSync: (Unity3D) Test
multiplayer without building 19

Communication Toolkit for


Modular UI—
MercuryMessaging
► Registering and unreigstering
events across components in Unity
is very painful
► Need to write many different and
unique callback functions to
handle modular UI components
► Mercury is a framework that fixes
this problem
Carmine Elvezio, Mengu Sukan, and Steven Feiner. “Mercury: A
Messaging Framework for Modular UI Components.” Proc, CHI 2018.
https://doi.org/10.1145/3173574.3174162

20

Feiner, COMS W4172, Spring 2024


Communication Toolkit for Modular UI—
MercuryMessaging

See the tutorial and download from


https://github.com/ColumbiaCGUI/Mercury
Messaging 21

Communication Toolkit for Modular UI—


MercuryMessaging

See the tutorial and download from


https://github.com/ColumbiaCGUI/Mercury
Messaging 22

Feiner, COMS W4172, Spring 2024


Thank You!
►Questions?

23

Feiner, COMS W4172, Spring 2024

You might also like