Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

175 views

Published on

Multiplayer games are indeed one of the most involving and addictive gaming experiences you could offer to anyone. Everything is simply more funny if you can challenge your friends! 🎮
Although nowadays Unity is hugely simplifying game development, when talking about making a real-time multiplayer game there are still some non-trivial concepts and different patterns to deal with ☝️
We will explore some of the "quirks and features" that Unity offers to the developers in support of this task, from the ready to use Matchmaker down to bit-a-bit messages serialization 👾

Github repo for the demo: https://github.com/BelkaLab/unity-networking-demo

Published in: Software
  • Be the first to comment

  • Be the first to like this

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

  1. 1. MOVING PIXELS ON SOMEONE ELSE'S SCREEN INTRODUCTION TO UNITY NETWORKING
  2. 2. HELLO 👋 Massimo Frasson Giovanni Frigo Computer Science student, Game developer @ Belka CTO & Co-founder of Belka
  3. 3. So, you want to develop a multiplayer videogame?
  4. 4. LET’S DO THIS!
  5. 5. The main objective: synchronizing things
  6. 6. The old-fashioned way 👶
  7. 7. The old-fashioned way #
  8. 8. The old-fashioned way 👴
  9. 9. The old-fashioned way 💀
  10. 10. Sounds like a lot of work!
  11. 11. TO THE RESCUE!
  12. 12. Network Stack in Unity You were here >Your scripts here<
  13. 13. Setting up a multiplayer scene
  14. 14. Setting up a multiplayer scene
  15. 15. Setting up a multiplayer scene
  16. 16. Setting up a multiplayer scene
  17. 17. Setting up a multiplayer scene
  18. 18. SYNCING THE STATE
  19. 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. 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-specific objects (position, rotation, animation..) • Simple variables (int, float, ..) • Everything serializable! (custom classes)
  21. 21. State sync Sets the Unique ID of this object on the network, so that we know who has changes
  22. 22. State sync: built-in objects
  23. 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. 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. 25. State sync: built-in objects This is cool! How can I replicate it also for more generic variables?
  26. 26. State sync: variables Let’s set a random color to each player and keep it synced!
  27. 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. 28. State sync: pretty much anything serializable! • Basic types (integers, strings, floats, …) • Unity types (Vector3, Color, …) • Serializable objects • Structs made up by types above
  29. 29. State sync: pretty much anything serializable! • Basic types (integers, strings, floats, …) • Unity types (Vector3, Color, …) • Serializable objects • Structs made up by types above Bonus: Lists of the primitive types above!
  30. 30. COMMANDS & RPC
  31. 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. 32. State sync: variables How can I set the color into the server? 🤔
  33. 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. 34. Commands The Client asks the server to perform an action The code is executed on the Server
  35. 35. Commands This is executed on server!
  36. 36. RPC The Server tells the client to execute some code The code is executed on each of the Clients
  37. 37. RPC
  38. 38. RPC Client
  39. 39. RPC Client Server
  40. 40. RPC Client Server Client
  41. 41. BUT ..it can get messy, if for each action you always have the RPC and Commands in the same file!
  42. 42. GOING FURTHER
  43. 43. Messages Used to send some info from a specific client to another
  44. 44. DEMO TIME! Belka Code: github.com/BelkaLab/unity-networking-demo
  45. 45. THANKS! Questions? @MaxFrax96 @john_frigo
  46. 46. @MaxFrax96 @john_frigo

×