Photon Unity Networking

Photon Unity Networking

Photon Unity Networking (PUN) is being put into Long Term Support mode as of July 2021. We are finishing Fusion, our state of the art, MonoBehaviour-based networking solution. Fusion is recommended for all recent and new projects!

PUN support will continue but there are no major changes planned. The Photon Cloud will also continue to support existing games indefinitely.
Download: PUN 2 Free from the Asset Store.

Overview
This package implements a comfortable Unity-specific networking API on top of Photon.
Keeping the API simple, this gives you dedicated servers, matchmaking, in-game communication, fixes, tweaks and ongoing support.
This package contains a setup wizard, the fully integrated API, Editor extensions and the client library. It’s compatible with the Photon Cloud Service, so you don’t even have to setup a server!

Requirements
Unity 2018.4 or up.

Server Options

667622--185613--cloud-banner.jpg

PUN 2
There are two “PUN 2” packages in the Asset Store: Both contain the same content, so everyone can just get and use the Free package. The Plus package includes a 100 CCU subscription, which is good for a bigger test group or an early soft launch (100 CCU cover approximately 40k monthly active users).

What’s new?! PUN 2 has a new structure and comes in just one “root” folder. We cleaned up the naming of many classes, fields and interfaces and there is a new callback system. We created new demos and are in the process of re-writing the documentation (note the v2 in the link). Currently the API reference is only in the package (see the PDF or CHM files). Updating existing projects will be quite some work. Here are the migration notes we took.

Should I update from PUN Classic? Definitely! PUN Classic is outdated.
Existing subscriptions (e.g. of a previously purchased PUN Classic Plus) can be used with PUN 2. There is no upgrade fee whatsoever.

Reply here or mail to: developer@photonengine.com.

Release History
(recent releases)

v2.47 (02. September 2024)
Fixed: PhotonNetwork.PunVersion to “2.47”. Accidentally v2.46 used “2.45” as well.
Updated: Library, Realtime and Chat API to 4.1.8.9. More details in the change logs.

v2.46 (26. April 2024)
Changed: PhotonStream serialization: Char values are cast to short before being sent (receivers will simply get a short but can cast accordingly).
Added: PhotonStream.Serialize(ref byte value).
Checked: Compatibility with Unity 2022.2.20 (soon to be Unity 6). All good.
Updated: Library, Realtime and Chat API to 4.1.8.4. More details in the change logs.

v2.45 (05. February 2024)
Fixed: OpJoinRandomOrCreateRoom and OpJoinRandomRoom. The last version introduced an issue with random matchmaking, when using MaxPlayers as filter to find rooms. It caused clients never to find fitting rooms in those conditions.
Updated: Library, Realtime and Chat API to 4.1.8.0.

v2.44 (14. December 2023)
Updated: Library, Realtime and Chat API to 4.1.7.4. Fixes and changes for Best Region Selection and reporting client timeouts to server. More in the related change logs.
Updated: PUN Wizard panel. Replaced forum link with pointer to join our Discord.

v2.43 (21. August 2023)
Updated: Library, Realtime and Chat API to 4.1.7.0. This includes many improvements for WebSockets and connection-loss debugging (specifically for UDP, SocketUdp class). More in the related change logs.
Updated: To Unity 2019.4.
Fixed: PUN Basics GameManager to not accidentally send the network Instantiate request before joining the room (which could happen if the scene was loading too fast). See comments in OnJoinedRoom().
Fixed: PUN Basics GUI Button call of LeaveRoom by removing the return value from the called method. It failed with the error “Method arguments are incompatible”. Adjusted related code (minimally).
Changed: Procedural Demo now randomizes the initial “seed” value. “Nice to have” addition.
Changed: Demo Hub to include Procedural Demo.

v2.42 (15. May 2023)
Updated: Library, Realtime and Chat API to 4.1.6.24. More details in the change logs.

v2.41 (02. August 2022)
Changed: PhotonHandler.MaxDatagrams to 10. The previous value was unnecessary low.
Changed: PhotonHandler sending to send more datagrams in the next frame, if it has more than MaxDatagrams queued in any frame.
Updated: Library, Realtime and Chat API to 4.1.6.17. More details in the change logs.

v2.40 (22. November 2021)
Fixed: Unity 2021.2 support. PhotonEditorUtils.IsPrefab now uses the correct prefab stage utility for Unity 2021.2 and up.
Changed: PhotonHandler.Dispatch is now catching exceptions. It will count them but only provide the first one’s callstack (to avoid log spamming).
Note: While the Photon lib caught exceptions in v4.1.6.10, that has not been a good solution. This new approach can be changed in source and is more flexible overall.
Changed: On Xbox, the peer classes no longer assume a native socket plugin exists. This was setting the UDP implementation to null in some cases, which failed to connect.
Updated: Library and Realtime to 4.1.6.11. More details in the change logs.

Release History
All updates are detailed in the changelog.txt in the package.

Download
PUN 2 in the Asset Store

Special thanks go to Jean, Vadim, Davin, Leepo, Hamza and Olli for their great work, feedback and support.

Upcoming
PUN is in Long Term Support (LTS) mode, which means we will support it for existing projects and keep it compatible with existing platforms. Of course, we keep the Photon Cloud compatible, too. However, bigger changes are no longer planned for PUN 2 anymore.

Photon Fusion is our state of the art, MonoBehaviour-based networking solution. Fusion is recommended for all recent and new projects.

Feedback is welcome! Just reply here. Mail us for complicated topics and console support.
This post will be edited over time with more info, updates, etc.

11 Likes

Woohoo, we now finally have a proper networking solution available in Unity.
(If I can bluntly say so myself ;))

Wow, that was a lot more than I expect way to go! Will be having a fun little tinker around :slight_smile:

Downloading and will take a look at the package now. I have just recently started playing with Photon, so if this behaves like it sounds, you have just saved me a lot of time!

Looking forward to see what changed from 0.93 to 1.0 :smile:

how is the promised linux version development going? (express edition should be out this month, according to roadmap)

You will be able to use “Photon Unity Networking” on any platform for Unite11 (end of next month).

Great update! :slight_smile:

Is it possible to create an authoritative setup with unity-builds launched on a dedicated hardware alongside photon to simulate movement and raycasting on the server with this new API?

So players won’t be able to start rooms (and only serverside unity builds will be able to do so) and their movement and shooting would be checked on server.

And the message flow would go like that: clients->photon->unity-build-for-collision-checking-attached-to-photon-like-a-client->photon->clients

…I hope that makes sense ).

Thats exactly what this extension is actually about with the “photon side client” being called master client.

The allowing only server to create room can also be easily done: only allow the real clients to join existing rooms by only using join room there and restrict createroom to the master clients you start on the server.

rooms created will show up in the room listing :slight_smile:

That was already possibel before. This new unity-builtin-netwoking like API is only affecting the client-side. The server-side is completely independent from the client-API. You can have clients, working with the “old” Photon for Unity APi, clients with this new approach, non-unity-clients, all communicating with the same servercode, even in the same rooms, so of course the client-api is not relevant for if you can use an authoritive approach on the server.

But attention with the authoritve approach: I would recommend to do some load testing rom time to time from the early stages of development on, as depending on the unity-features, you use, even headless-unity instances on the server can get really expensive in terms of cpu if you simualte all movements of a lot of clients in realtime with them.

For example movement physics in general (not unity-specific, I even do not know, if unity has builtin physiscs or if this would have to be done by a 3rd party middleware anyway) can easily get quite expensive.
If your client only needs 5% of its cpu power for physics (which by far isn’t a critical number for the client), a server with 10 times as much cpu as the client would already run at 100%, if it has to do the same calculations for just 200 clients.

So you should think about if some serverside expensive game-logic is really needed, before using so much server-side ressources for it, that your server is at its limits with just a few users, although it could handle thousands without that expensive game-logic, or if a simpler logic would also do it.

yupp unity has PhysX integrated, thats why it holds even more, you can assume that a game with 32 players requires a 3ghz core of a i5 / i7 cpu on its own in an FPS or similar heavy title, especially if you use physical projectiles, not ray predictions.

A quick question: Does this help you with integrating the physics/game logic parts from unity that you might need to make an authorative server that has control over movement? I downloaded the example and messed around with it, but it just seems like the only thing you’ve built is a game chat / room server that uses relaying to send the data between clients, trusting clients to not cheat as the server has zero control over the clients positions/actions?

Thanks all for this great product !

fholm:
The server is currently just organizing your players into games and then relays everything.
So far, the server does not understand what’s going on in Unity. It would need the levels, the physics engine (which is not deterministic across platforms) and most of all, the server needs to know what sort of cheating has to be detected and how. And then, there’s corrections.

It’s usually not a good idea to run a full blown physics environment on the server for every room (or the complete world), just to check if positions are reported correctly.
The cheapest way to check this is using one of the clients - the host or MasterClient maybe. Or, if absolutely necessary, you could run a Unity headless instance to correct the players.

I would try to check only a limited set of data from the client. Maybe when the client reports his new score, check if it’s possible to reach that score, if the player played at all and if you like, make all clients report all player’s scores at the end of the game. Make sure noone can submit scores every second.

Most of this really depends on the game and is not solved out of the box. But we do most of the rest and now you can. :wink:

When I try to launch Photon from the package I get the following error (please see the image attached).

I think I’ve never used Photon on that hardware before - so I suppose I miss .net framework or smth like that (what should I install?).

thanks,
Slav

669658--24018--$error_photon.png

gnoblin:
This looks like missing DotNet framework, yes.
You could use this installer: http://www.microsoft.com/download/en/details.aspx?id=17851

Hi, got this error when start server

2124: 02:07:05.468 - —
2124: 02:07:05.468 - Service: “Photon Socket Server” starting
2124: 02:07:05.468 - Config File: C:\Documents and Settings\Bruno\Desktop\Photon-Server\bin_Win32_xp\PhotonServer.config
2124: 02:07:05.468 - Will NOT produce crash dumps
2124: 02:07:05.468 -
2124: 02:07:05.468 - WARNING: ***************************************************************
2124: 02:07:05.468 - WARNING: Photon has been built to operate on an operating system earlier than Windows Vista.
2124: 02:07:05.468 - WARNING: Performance will not be as good as when built for Windows Vista or later.
2124: 02:07:05.468 - WARNING: ***************************************************************
2124: 02:07:05.468 -
2124: 02:07:05.468 - Server Starting…
2124: 02:07:05.468 - CService::OnException() - Exception: CJob::IsProcessInJob() - Accesso negato.
2124: 02:07:05.468 - Server shutting down…
2124: 02:07:05.468 - Shutting down socket servers…
2124: 02:07:05.468 - Destroying ENet thread pool
2124: 02:07:05.468 - Destroying TCP inactivity timer
2124: 02:07:05.468 - Destroying Business logic thread pool
2124: 02:07:05.468 - Destroying servers
2124: 02:07:05.468 - Destroying TCP Outbound Connection Manager
2124: 02:07:05.468 - Destroying resolver
2124: 02:07:05.468 - Destroying TCP Proxy Connection Manager
2124: 02:07:05.468 - Destroying ENet host
2124: 02:07:05.468 - Destroying CLR dispatcher
2124: 02:07:05.468 - Destroying CLR applications
2124: 02:07:05.468 - Destroying I/O thread pool
2124: 02:07:05.468 - Destroying ENet buffer allocator
2124: 02:07:05.468 - Destroying TCP buffer allocator
2124: 02:07:05.468 - Destroying TCP socket allocator
2124: 02:07:05.468 - Destroying ENet socket allocator
2124: 02:07:05.468 - Destroying performance counters
2124: 02:07:05.468 - Shutdown complete…

Package on asset store doesn’t contain source code for serverside app(s) - should I just take lite app sources from previous releases? (I’d like to add some logic on the server and not just send data from client to client). Sorry if I misunderstood something :).

What is the difference between Master, Game1 and Game2 apps? (is there any place I missed where I can read about it?)

thanks,
Slav

Master is the master server (you talk to it initially, hides the policy server behind it and in the end forwards you to the actual server (Game1 / Game2) that handle your room in the end which are used for load balancing and can technically even be distributed to other machines