Photon Networking Guide

Photon Networking Guide

Download from the Asset Store:
Photon Networking Guide | Network | Unity Asset Store

Get the details from Leepo below :).

Introduction
Based on my best selling asset store package for Unity networking, The ultimate unity networking project, I am now introducing the Photon Unity Networking Guide (PUN)! Learn how to add multiplayer to your Unity games, no previous multiplayer experience required.

Server hosting: This package is includes 6 months of hosting for one application (100CCU professional, worth $114).
Contents: Includes 27 pages documentation, 14 tutorials and examples and in-depth background information. All in C# code, however PUN is fully compatible with JS so all lessons learned are easily transferable to JS.
Updates: The project is maintained for at least Unity 3.X. If new important PUN features are added I’ll include new examples to this project which you’ll get for free by updating via the asset store.
Re-usable: This package comes with full documentation introducing you to PUN and teaching you by using various examples. Much of the example code is useful for re-se in your own games.

How is Photon Unity Networking different from Unity Networking?
Unity networking works very well for small games, but for serious networking games the connectivity problems and bad connections are troublesome.
I have developed the PUN plugin with as goal to create a Photon based networking implementation that’s even easier to use then Unity networking, but far more powerful. PUN is a free plugin available on the asset store. PUN has to be combined with a Photon server OR by using the Photon cloud service.

How is this guide different from the M2H Unity networking tutorial?
This guide is based on my asset store Unity networking project. The code and texts have been rewritten to work with PUN, the texts have been improved and the code has been made even cleaner&clearer. Furthermore new PUN specific parts have been added to introduce powerful PUN features.

Table of contents:
Introduction
Basic PUN concepts
Getting started
Tutorials:
Tutorial 1: Connecting
Tutorial 2: Sending messages using PhotonViews
Tutorial 3: Authoritative servers
Tutorial 4: Manually instantiating PhotonViewIDs
Examples
Example 1: Chatscript
Example 2: Game list
Example 3: Lobby system
Example 4: FPS game
Example 5: Multiplayer without any GUI
Extras:
Network Culling code
Further network subjects explained

  1. Best practices
  2. Interest management (using PhotonView.group)
  3. Anti cheating
  4. Manually allocate PhotonView ID’s
  5. Manual cleanup: PhotonNetwork.autoCleanUpPlayerObjects=false
  6. Connectivity
  7. Network and level loading
  8. Room properties
  9. Versioning: keeping different game versions separated
  10. Improve performance
  11. Statistics
    Unity tips
    Feedback
    Feedback is very welcome. If you feel like something is missing let me know.

Download

Download from the Unity asset store

Hi today i buy Photon Networking Guide where is licence 6 months of hosting for one application (100CCU professional)

1 Like

Heya, thank you for your purchase.

I forgot to attach the instructions to the project, unfortunately the subscribtion cannot be activated automatically, you need to send an email:

I have updated the asset store pacakage to include these instructions in the readme, and also updated the included PUN version to the latest (v1.12).

Hi i have error today in code Photon Networking Guide .After one good connection ,second connection give me this error !!!

InvalidCastException: Cannot cast from source type to destination type.
Connect1C.OnReceivedRoomList () (at Assets/PUNGuide_M2H/_Tutorial 1/Scripts/Connect1C.cs:108)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[ ]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1336)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1158)
ExitGames.Client.Photon.PeerBase:smile:eserializeMessageAndCallback(Byte[ ])
ExitGames.Client.Photon.EnetPeer:smile:ispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:smile:ispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:79)

Please change line 108:

“foreach(Room room in PhotonNetwork.GetRoomList()){”
“foreach(RoomInfo room in PhotonNetwork.GetRoomList()){”

I’ll include this fix in the next update.

Hi

from what I understand the Photon Cloud is not really suitable for staging a FPS game with, say, eight players. Is this right?
It could only be achieved if Photon is installed on a VPS?

R

It’s perfectly sutiable for an FPS game, 16 players should also still be fine.
However, what you are missing in the cloud is server side logic, so you should be OK with a setup where one of your clients acts as the authorative client. Otherwise, you’ll need to host the Photon server(s) yourself indeed.

Thanks Leepo

I am developing something where there is only simple movement and chat - I am not worried about cheating - so I wont need to worry about auth servers.

My avatars are simple too.

So the Cloud should be ok?

I am confused about rooms and messages per second tho.

If an avatar moves then the send rate can be 10 messages a second to the Cloud? Then if there are 10 other players, then the Cloud will need to send these moves to them. So that is about 110 messages in one second to convey one players move?

Isn’t the Cloud limited to 500 messages a second?

Also with rooms - are they instances of a game? Is this right?

thanks for your help :slight_smile:

Some clarifications:

  1. We currently do not limit the message rate (msg/s). At a certain point we may have to put a limit on it.
  2. Msg/s is an average across all rooms.
  3. We will soon display the msg/s counter in the Dashboard - so you see what you generate.
  4. We will allow to outnumber the limit. Currently this is free - and if we charge for it it will be super fair (as our current pricing).

Photon Unity Networking (PUN) is configured for 10 updates/s. So with 10 players in a room you have about 10 msg/s * 10 * 10 = 1000 msg/s. This is indeed more than the limit - but do not worry too much about it now.

Chris

From my perspective absolutely.

From a implementation perspective…in most cases a room stands for a game that is currently playing, yes.But you can of course choose to use a Photon room for a lobby-chat, or whatever.

Thanks Bertelmonster2k for your reply.

So I would buy the $9 a month Indie license initially. I would like at least 20 people to be able to move and chat around my game level.

So this would generate a minimum of 2000 messages per second on the Cloud.

Your pricing states that there is a limit of 300 msg/per second for the 100 indie license.

But you are saying that I do not have to worry about this for now? When would this become an issue?

thanks

Just do not worry and get your app running. We do no have plans to cut it for now.

Just bought the Photon Networking Guide, very interested in learning Multiplayer via Photon.

Only just started but I already have an error while playing with “Tutorial 2: Sending messages using PhotonViews”.
When I try to connect the second client to the master client I get the following error:

createGame failed, client stays on masterserver: OperationResponse 227: ReturnCode: 32766 (A game with the specified id already exist.). Parameters: {}.
UnityEngine.Debug:LogError(Object)
PhotonHandler:smile:ebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)
NetworkingPeer:smile:ebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:700)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:831)
ExitGames.Client.Photon.PeerBase:smile:eserializeMessageAndCallback(Byte[ ])
ExitGames.Client.Photon.EnetPeer:smile:ispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:smile:ispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:79)

What did I mess up to cause this already? :wink:

Edit: Sorry, just assumed the fix above (posted by aleksbgs) was already updated in the project. It’s working now.

Another quick note about “Tutorial 2: Sending messages using PhotonViews”.
In the third piece of text it states “the master client is automatically the of all Photonviews”.
I guess something is missing between “the” and “of”?

these photo networking guides are awesome.i really like.

@Tim:
Sorry for the confusion. I have fixed the document but that too will be live only with a new update.
(Hilversum he?, zie je misschien bij een volgende GGJ daar!)

Considering switching to Photon from SmartFoxServer. The one thing I see that concerns me, is the 300 Msg/s. As stated above, 10 players would already be 1000 Msg/s? Yet the first indie license is good for 100 CCU. I do not understand how that matches up, if we have 100 CCU but can only have 300 Msg/s.

We are developing an indie MMOG where players will explore environments, chat, customize characters, buy and collect items in the game and build their own spaces. I am fine with having 100 CCU to start out but is it not even possible due to the Msg/s restrictions?

We are not restrict on the msg/s (this is per room!) restriction and do not plan to do so. We may have to cut off at a very high limit.

A Few Questions

Were starting a new game soon which will be multiplayer. After looking at the viking demo this looks to be what we need. My question is will someone on an iPad or iPhone be able to connect to the same game as someone on a PC or Webplayer? The only thing that needs to happen is all the players can walk around and talk to each other. Also can you check the room capacity? Example check how many people are in the room and limit that, and not allow new players to join that room?

will someone on an iPad or iPhone be able to connect to the same game as someone on a PC or Webplayer?

Yes, sure. You can communicate between all the platforms we support client side.
If you did cross platform to Flash (AS3 library) or JavaScript (for HTML5 games) you could do it but have to stick with the data types these languages support too. Aside from that: Not a problem.

check how many people are in the room and limit that, and not allow new players to join that room?
Sure. You can set MaxPlayers per room creation. This is available in the room listing, together with the current player count. Even if a room is not at max capacity, you can close and or hide it. We don’t have passwords but some are using properties for that.

Have a look at the demos from the Asset Store. They are free and setup within minutes.