SlideShare a Scribd company logo
1 of 46
Download to read offline
MOVING PIXELS ON
SOMEONE ELSE'S
SCREEN
INTRODUCTION TO UNITY NETWORKING
HELLO šŸ‘‹
Massimo Frasson
Giovanni Frigo
Computer Science student,
Game developer @ Belka
CTO & Co-founder of Belka
So, you want to develop
a multiplayer videogame?
LETā€™S DO THIS!
The main objective:
synchronizing things
The old-fashioned way
šŸ‘¶
The old-fashioned way
#
The old-fashioned way
šŸ‘“
The old-fashioned way
šŸ’€
Sounds like a lot of work!
TO THE RESCUE!
Network Stack in Unity
You were
here
>Your scripts here<
Setting up a multiplayer scene
Setting up a multiplayer scene
Setting up a multiplayer scene
Setting up a multiplayer scene
Setting up a multiplayer scene
SYNCING THE STATE
Server + Client 1
State sync: built-in objects
NetworkManager Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client 2
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client n
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Scene
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
State sync
The Network Identity component
controls a GameObjectā€™s unique
identity on the network, and it
uses that identity to make the
networking system aware of the
GameObject.
ā€¢ Unity-speciļ¬c objects (position, rotation,
animation..)
ā€¢ Simple variables (int, ļ¬‚oat, ..)
ā€¢ Everything serializable! (custom classes)
State sync
Sets the Unique ID of this
object on the network, so that
we know who has changes
State sync: built-in objects
Server + Client 1
State sync: built-in objects
NetworkManager Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client 2
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client n
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Scene
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Server + Client 1
State sync: built-in objects
NetworkManager Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client 2
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Client n
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player 2
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
Player n
ā€¦ā€Ø
ā€¢ NetworkIdentityā€Ø
ā€¢ NetworkTransform
NetworkTransformā€Ø
updates
Scene
State sync: built-in objects
This is cool!
How can I replicate it also for more
generic variables?
State sync: variables
Letā€™s set a random color to each player and keep it
synced!
State sync: variables
The [SyncVar] attribute tells the
server that once the variable is
changed on the server, it should also
inform everyone else about it
State sync: pretty much
anything serializable!
ā€¢ Basic types (integers, strings, ļ¬‚oats, ā€¦)
ā€¢ Unity types (Vector3, Color, ā€¦)
ā€¢ Serializable objects
ā€¢ Structs made up by types above
State sync: pretty much
anything serializable!
ā€¢ Basic types (integers, strings, ļ¬‚oats, ā€¦)
ā€¢ Unity types (Vector3, Color, ā€¦)
ā€¢ Serializable objects
ā€¢ Structs made up by types above
Bonus: Lists of the primitive types above!
COMMANDS & RPC
State sync: variables
Server + Client 1
NetworkManager Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Client 2
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Client n
Other scene objects
(terrain, camera, light)
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Color SyncVarā€Ø
updates
Scene
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
State sync: variables
How can I set the color into the server?
šŸ¤”
State sync: variables
Server + Client 1
NetworkManager Other scene objects
(terrain, camera, light)
Client 2
Other scene objects
(terrain, camera, light)
Client n
Other scene objects
(terrain, camera, light)
Scene
CmdChangeColor
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 1
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player 2
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Player n
ā€¦ā€Ø
ā€¢ ColorControllerā€Ø
-[SyncVar] Color
Commands
The Client asks the server to perform an
action
The code is executed on the Server
Commands
This is executed on server!
RPC
The Server tells the client to execute some
code
The code is executed on each of the Clients
RPC
RPC
Client
RPC
Client
Server
RPC
Client
Server
Client
BUT
..it can get messy, if for each action
you always have the RPC and
Commands in the same ļ¬le!
GOING FURTHER
Messages
Used to send some info from a
speciļ¬c client to another
DEMO TIME!
Belka
Code: github.com/BelkaLab/unity-networking-demo
THANKS!
Questions?
@MaxFrax96
@john_frigo
@MaxFrax96
@john_frigo

More Related Content

What's hot

Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game Design
Prashant Warrier
Ā 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
Duy Tan Geek
Ā 
Game Project / Working with Unity
Game Project / Working with UnityGame Project / Working with Unity
Game Project / Working with Unity
Petri Lankoski
Ā 

What's hot (20)

Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
Ā 
Deterministic Simulation - What modern online games can learn from the Game B...
Deterministic Simulation - What modern online games can learn from the Game B...Deterministic Simulation - What modern online games can learn from the Game B...
Deterministic Simulation - What modern online games can learn from the Game B...
Ā 
Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game Design
Ā 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
Ā 
Data Ward Pitch, v1.0
Data Ward Pitch, v1.0Data Ward Pitch, v1.0
Data Ward Pitch, v1.0
Ā 
2D Video Games with MacRuby
2D Video Games with MacRuby2D Video Games with MacRuby
2D Video Games with MacRuby
Ā 
Games on Demand: Are We There Yet?
Games on Demand: Are We There Yet?Games on Demand: Are We There Yet?
Games on Demand: Are We There Yet?
Ā 
Escape: Level Design Exercise in Unity
Escape: Level Design Exercise in UnityEscape: Level Design Exercise in Unity
Escape: Level Design Exercise in Unity
Ā 
Developing Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3DDeveloping Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3D
Ā 
Unity 3d Basics
Unity 3d BasicsUnity 3d Basics
Unity 3d Basics
Ā 
Flowcharts
FlowchartsFlowcharts
Flowcharts
Ā 
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchBringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Ā 
Computer Games Inner Workings - I. Loukeris AIT
Computer Games Inner Workings - I. Loukeris AITComputer Games Inner Workings - I. Loukeris AIT
Computer Games Inner Workings - I. Loukeris AIT
Ā 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
Ā 
Game development -session on unity 3d
Game development -session on unity 3d Game development -session on unity 3d
Game development -session on unity 3d
Ā 
Presentasi Seminar Unity (AMIKOM Game Dev)
Presentasi Seminar Unity (AMIKOM Game Dev)Presentasi Seminar Unity (AMIKOM Game Dev)
Presentasi Seminar Unity (AMIKOM Game Dev)
Ā 
Game Project / Working with Unity
Game Project / Working with UnityGame Project / Working with Unity
Game Project / Working with Unity
Ā 
Introduction to Unity3D Game Engine
Introduction to Unity3D Game EngineIntroduction to Unity3D Game Engine
Introduction to Unity3D Game Engine
Ā 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game Engine
Ā 
Casual and Social Games with Unity
Casual and Social Games with UnityCasual and Social Games with Unity
Casual and Social Games with Unity
Ā 

Similar to Moving pixels on someone else's screen: introduction to Unity networking

Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)
Rajkumar Pawar
Ā 
GamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemGamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming System
Academia Sinica
Ā 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
slantsixgames
Ā 

Similar to Moving pixels on someone else's screen: introduction to Unity networking (20)

Photon Session / Unite12 Conference
Photon Session / Unite12 ConferencePhoton Session / Unite12 Conference
Photon Session / Unite12 Conference
Ā 
Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)
Ā 
Cocos2d game programming 2
Cocos2d game programming 2Cocos2d game programming 2
Cocos2d game programming 2
Ā 
Cocos2d programming
Cocos2d programmingCocos2d programming
Cocos2d programming
Ā 
2004: Sƶldner - a Post Mortem
2004: Sƶldner - a Post Mortem2004: Sƶldner - a Post Mortem
2004: Sƶldner - a Post Mortem
Ā 
GamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemGamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming System
Ā 
Supersize Your Production Pipe
Supersize Your Production PipeSupersize Your Production Pipe
Supersize Your Production Pipe
Ā 
98 374 Lesson 02-slides
98 374 Lesson 02-slides98 374 Lesson 02-slides
98 374 Lesson 02-slides
Ā 
Unity workshop
Unity workshopUnity workshop
Unity workshop
Ā 
East Coast DevCon 2014: Game Programming in UE4 - Game Framework & Sample Pro...
East Coast DevCon 2014: Game Programming in UE4 - Game Framework & Sample Pro...East Coast DevCon 2014: Game Programming in UE4 - Game Framework & Sample Pro...
East Coast DevCon 2014: Game Programming in UE4 - Game Framework & Sample Pro...
Ā 
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Ā 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
Ā 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development document
Ā 
GDC 2015 ć§ć®ćƒć‚¤ć‚Øćƒ³ćƒ‰ć‚°ćƒ©ćƒ•ć‚£ćƒƒć‚Æć‚¹
GDC 2015 ć§ć®ćƒć‚¤ć‚Øćƒ³ćƒ‰ć‚°ćƒ©ćƒ•ć‚£ćƒƒć‚Æć‚¹GDC 2015 ć§ć®ćƒć‚¤ć‚Øćƒ³ćƒ‰ć‚°ćƒ©ćƒ•ć‚£ćƒƒć‚Æć‚¹
GDC 2015 ć§ć®ćƒć‚¤ć‚Øćƒ³ćƒ‰ć‚°ćƒ©ćƒ•ć‚£ćƒƒć‚Æć‚¹
Ā 
XNA for Windows Phone
XNA for Windows PhoneXNA for Windows Phone
XNA for Windows Phone
Ā 
De Re PlayStation Vita
De Re PlayStation VitaDe Re PlayStation Vita
De Re PlayStation Vita
Ā 
Computer Games Development Chapter 7
Computer Games Development Chapter 7Computer Games Development Chapter 7
Computer Games Development Chapter 7
Ā 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Ā 
Scalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer gamesScalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer games
Ā 
Unity
UnityUnity
Unity
Ā 

Recently uploaded

Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Andrea Goulet
Ā 
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Q-Advise
Ā 

Recently uploaded (20)

How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
Ā 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
Ā 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
Ā 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
Ā 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
Ā 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
Ā 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesis
Ā 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
Ā 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Ā 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
Ā 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Ā 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
Ā 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Ā 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Ā 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
Ā 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
Ā 
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of workā€Æ_PDF.pdf
Ā 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
Ā 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
Ā 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
Ā 

Moving pixels on someone else's screen: introduction to Unity networking

  • 1. MOVING PIXELS ON SOMEONE ELSE'S SCREEN INTRODUCTION TO UNITY NETWORKING
  • 2. HELLO šŸ‘‹ Massimo Frasson Giovanni Frigo Computer Science student, Game developer @ Belka CTO & Co-founder of Belka
  • 3. So, you want to develop a multiplayer videogame?
  • 10. Sounds like a lot of work!
  • 12. Network Stack in Unity You were here >Your scripts here<
  • 13. Setting up a multiplayer scene
  • 14. Setting up a multiplayer scene
  • 15. Setting up a multiplayer scene
  • 16. Setting up a multiplayer scene
  • 17. Setting up a multiplayer scene
  • 19. Server + Client 1 State sync: built-in objects NetworkManager Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client 2 Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client n Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Scene Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform
  • 20. State sync The Network Identity component controls a GameObjectā€™s unique identity on the network, and it uses that identity to make the networking system aware of the GameObject. ā€¢ Unity-speciļ¬c objects (position, rotation, animation..) ā€¢ Simple variables (int, ļ¬‚oat, ..) ā€¢ Everything serializable! (custom classes)
  • 21. State sync Sets the Unique ID of this object on the network, so that we know who has changes
  • 23. Server + Client 1 State sync: built-in objects NetworkManager Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client 2 Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client n Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Scene Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform
  • 24. Server + Client 1 State sync: built-in objects NetworkManager Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client 2 Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Client n Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player 2 ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform Player n ā€¦ā€Ø ā€¢ NetworkIdentityā€Ø ā€¢ NetworkTransform NetworkTransformā€Ø updates Scene
  • 25. State sync: built-in objects This is cool! How can I replicate it also for more generic variables?
  • 26. State sync: variables Letā€™s set a random color to each player and keep it synced!
  • 27. State sync: variables The [SyncVar] attribute tells the server that once the variable is changed on the server, it should also inform everyone else about it
  • 28. State sync: pretty much anything serializable! ā€¢ Basic types (integers, strings, ļ¬‚oats, ā€¦) ā€¢ Unity types (Vector3, Color, ā€¦) ā€¢ Serializable objects ā€¢ Structs made up by types above
  • 29. State sync: pretty much anything serializable! ā€¢ Basic types (integers, strings, ļ¬‚oats, ā€¦) ā€¢ Unity types (Vector3, Color, ā€¦) ā€¢ Serializable objects ā€¢ Structs made up by types above Bonus: Lists of the primitive types above!
  • 31. State sync: variables Server + Client 1 NetworkManager Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Client 2 Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Client n Other scene objects (terrain, camera, light) Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Color SyncVarā€Ø updates Scene Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color
  • 32. State sync: variables How can I set the color into the server? šŸ¤”
  • 33. State sync: variables Server + Client 1 NetworkManager Other scene objects (terrain, camera, light) Client 2 Other scene objects (terrain, camera, light) Client n Other scene objects (terrain, camera, light) Scene CmdChangeColor Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 1 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player 2 ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color Player n ā€¦ā€Ø ā€¢ ColorControllerā€Ø -[SyncVar] Color
  • 34. Commands The Client asks the server to perform an action The code is executed on the Server
  • 36. RPC The Server tells the client to execute some code The code is executed on each of the Clients
  • 37. RPC
  • 41. BUT ..it can get messy, if for each action you always have the RPC and Commands in the same ļ¬le!
  • 43. Messages Used to send some info from a speciļ¬c client to another