I just recently integrated Photon into our project. While you don’t get to use UE4’s own replication system, you are overall getting a much easier experience. Some basic C++ knowledge is all you need to get going (I myself just studied learncpp.com for a little more than a week; my advantage though was already being proficient with Blueprints, as they essentially are just C++ scripting), and you simply don’t have to worry about server side at all.
First, make sure you get an AppID from Photon’s site.
Then, completely ignore all their SDK stuff! Not kidding! Everything you need is already in their demo!
Download the Photon demo for UE4:
Study their system, make changes of your own, play around with things like custom replication.
For getting it into your project, the easiest way is to copy all the code into your project and create a similar setup (like the PhotonLBClient BP created from the PhotonLBClient C++ actor class, creating similar classes with the “Add Code to Project” option in UE4 like BaseView, LoadBalancingListener, import.h, etc.), then start tailoring things to your needs and stripping out unnecessary code.
An quick but comprehensive example for adding the demo features to your project would be:
- Look at the file paths in the project files for the demo. You’ll notice an extra directory in the Source folder, called Photon. Simply copy+paste that Photon folder into the Source folder of your project.
- Edit the [project].build.cs file of your project to include the code from the demo’s [project].build.cs. This code is responsible for your project including all the Photon static library content. Obviously (or maybe not obviously if you are new to C++), only copy the extra content from the demo that has to do with linking in the Photon libraries; in other words, compare the two build.cs files and don’t copy anything that is already in your own project.
- Create all C++ classes that you see in the demo (LoadBalancingListener, DemoConstants, PhotonLBClient [make this one an actor], BaseView) and copy all code over to them, paying attention to .h and .cpp (don’t mix em up!).
- In the demo project Source files, there is an import.h (or something like that) file that won’t show up in VS. Make a new class, like ImportPhoton, and copy the contents of import.h (again, it’s something like that) into your new ImportPhoton.h.
- In LoadBalancingListener.h, make sure to do an include for ImportPhoton.h (#include “ImportPhoton.h”), and make sure the only includes are for that and BaseView.h. Comment out any other includes beyond those two. The lovely people at ExitGames already left a comment there about how LoadBalancingListener is the only include point for the Photon static libraries. The code you copied into your ImportPhoton.h will handle that when you do the include.
- In UE4, make a BP from the PhotonLBClient C++ actor. Now your Photon features can be handled all through a single BP! Since you copied the code from the demo into your PhotonLBClient C++ actor, you will have some features ready to go. You’ll want to copy+paste your Photon AppID into the corresponding box in the Details pane of the BP. Now you have permission to connect to Photon.
You’re good to go! Fix any errors that could come from not copying things correctly. You might also have to fix some weird stuff having to with DemoConstants.
The main thing here is that you get everything going, and THEN start stripping features left over from the demo and integrating your own custom features based on what’s there. I’ve only just started customizing these features and creating new functions of my own that utilize Photon (making everything Blueprintable, of course! Blueprints are the way to go any time you have the option, imho), so I’m no expert, but I can already tell it is QUITE easy to use and that the server works beautifully. It’s a truly front-end experience for online multiplayer, which is fantastic for indie groups like us who don’t have the resources to develop our own networking.