Game Dev

Multiplayer Customization

The player customization now properly replicates on the different clients playing in the same Photon room.

Screenshot 2019-04-06 at 17.21.20.png
3 players with different customisation 🙂

The customization logic is nearly done. Here is what’s missing:

  • Possibility to buy coins when you don’t have enough. It will be the main in-app purchase requiring people to give me real money 😐
    But it’s also possible to collect the coins just by playing the game of course.
  • More things to customise (and buy…). For now I have 2 guns, 4 swords, 10 colors, 5 tie colors, 5 cloths, 2 super attacks and 2 type of upgrades (health, dash). I’ll try to add some more (especially guns and cloths).

 

Screenshot 2019-04-06 at 17.35.17.png

I can’t wait to try this with actual people! Doing it by myself makes my multiplayer testing abilities quite limited!

Advertisements
Game Dev

Moving to Photon

Some more refactoring? Yay!

I was finally done with my previous networking refactoring and I was back on features already, right? But! I mentioned something in previous posts that made me think again about networking: UNet is being deprecated by Unity. And my whole networking strategy was based on it. I was so blindly using what was there out of the box and I didn’t consider other alternatives such as Photon before. Let’s fix that 😐

Photon is a bit like a platform for multiplayer as a service (MAAS – I just invented it). It helps us focus on the gameplay when they provide top features for our multiplayer: from the lobby and room management to the Remote Procedure Calls (RPC), events for syncing vars, and plenty of nice callbacks to make it alive (player entered/left a room…). Check it for yourself: https://www.photonengine.com

Before I go any further, I should mention I’m only referring here to Photon Pun v2. Photon has multiple products (Pun, Bolt, Quantum) for different needs you may have (simple TPS, zero lag realtime multiplayer and so on). Pun is a solution made to ease the realtime integration with Unity.

I’m sure my point of view will evolve as my understanding does, but I’ve been seriously looking into it for few days (around 20h just last weekend). So far, here are my own pros & cons about “Moving to Photon” I considered for my final choice:

PROS

  • Photon is really well documented! When I was getting information for UNet, I didn’t find such good materials (Pun documentation).
  • Unlike UNet, Photon Pun is not deprecated and just released end of last year a v2.
  • Photon Pun looks easier to integrate from a first look. Unlike UNet, we don’t have to add the prefabs to a NetworkManager whenever you want to spawn those over the network. Photon will expect you to put those prefabs in “Resources” folders that can be anywhere in your project. Convenient. No “command” (functions executed on the server only). Working with those with UNet was a pain, considering only players were able to call those.
  • No player is considered as the “Server”. Instead, a client will be the “Master Client”. The difference lies with the fact a Master Client can be reassigned when he leaves the game while when the Server falls, the game itself is over. When playing with a friend, it’s not a big deal, but when doing some matchmaking it can be quite annoying.
  • Offline mode for single player is just “PhotonNetwork.OfflineMode = true”. With UNet you can do it but it’s not that straightforward!
  • UNet and Pun concepts are not too far. To be honest, to do my initial tests I created a new branch and went berserk doing this kind of replace (“replace all” when possible):
    • “using UnityEngine.Networking;” => “using Photon.Pun”
    • “NetworkServer.Spawn(prefab” => “PhotonNetwork.Instantiate(prefab.name”
    • “IsLocalPlayer” => “photonView.IsMine”
    • “IsServer” => ” PhotonNetwork.IsMasterClient”
    • “[ClientRpc]” => “[PunRpc]
      Then in the editor:
    • “Network Identity” => “Photon View”
    • “Network Transform” => “Photon View Transform”
    • … (check this post for a real list : Photon Blog)

CONS

  • With UNet you can do multiplayers locally in your own network. With Photon, forget that. You have to be connected to Internet to play with people, even if they sit right next to you.
  • Unity is working on a new solution to address the topic. I guess they will do something big and probably cost effective. But as of today I didn’t find enough material to convince me to wait for the big picture.
  • If you did your game with UNet already, it may be a real pain to refactor it. I still believe I can do that in few days but it depends on the project.

Well, I did the move already. I’m currently fixing the issues on my main character. But nothing serious so far. I’m doing the network for the third time already. Looks crazy but I still enjoy working on this project even if it goes back and forth, so I’ll just follow my intuitions there again and adjust.

Screenshot 2019-03-13 at 00.27.33
Back to basics

Note: One of the tutorials that gave me a first look into Pun is the following: PUN 2 Unity Multiplayer Networking #1 to #3. It helped a lot understanding the basics. BUT there are some mistakes in there so you should be careful if you follow it (scene loading, player instantiations, wrong info on serialisable types…). Still it was a good start.