Unity + Photon troubleshooting

Camilo Diaz

INTRODUCTION 

This is a compilation of my experiences developing a collaborative VR application on Unity and Photon plugin. I go through a series of  steps on how to work in a multiplayer environment and how to solve some errors.

FIRST OF ALL - WHAT IS PHOTON ENGINE?

Some of us have the misconception that photon is similar a version of Unity, but for multiplayer games. It's not. It is a service in the cloud that host your application-server side logic so you don't have to deal with networking heavy lift issues such as synchronization, timeouts, packet management, etc.

Unity is a game engine responsible for rendering, physics, update animations and manage user interaction, in other words the client side logic. Every time you update a game object position, activate a button or destroy any element in the scene you need to send that information over the net to the server, and the server synchronizes the information across all the clients. This is what Photon does.

THE BEST OF ALL IT'S FREE AND YOU CAN USE AS MANY APPS AS YOU WANT IN MULTIPLAYER MODE. THE ONLY LIMITATION IS THE NUMBER OF PLAYERS CONNECTED TO THE SERVER. 

You don't need to deal with server side configurations ( well, this is not entirely truth, but the settings you need to change are minimum), you just send the information to the server. This will save you a lot of time. 

How to install Photon Plugin in Unity

There are multiple tutorials on how to do this, most of them miss a few steps or are outdated (from 2016).



ISSUE: 

After installing Photon plugin, Unity did not pop any window up asking for APP ID

Workaround:

Unfortunately, There is no easy fix for this. Something  got burned in your Unity configuration files and it picks the Photon APP ID as a default in every project. This is the worst case scenario. Basically, I had to install a new Unity version, create a new project and move all the elements from the previous Unity install, and reinstall Photon Plugin. There are posts from back 2019 reporting this issue and it has not been fixed in 2023.

VIDEO TUTORIALS

The best video series on how to write a VR multiplayer application in Unity is this one:

Part 1 (Installation and setup and spawning networking game objects)

https://www.youtube.com/watch?v=KHWuTBmT1oI&t=387s&ab_channel=Valem

Part 2 (stream positions and game object ownership)

https://www.youtube.com/watch?v=DB5bajOMdUQ&t=195s&ab_channel=Valem

Part 3 (create multiple rooms )

https://www.youtube.com/watch?v=9Zqcv9k9cg0&t=903s&ab_channel=Valem

Make sure to watch all the videos before jumping to implementation. The creator corrects himself A LOT from one video to the other. So you might find yourself in issues that he solves at the end of the video or in part 3. 

Also, he uses Unity 2019 and the latest LTR is 2021. Some things have changed since then:

THIS IS VERY IMPORTANT

Keep the Photon View transform component in the Root game object. If you need to update local transformations ( specific parts of the body ) then add another Photon View transform to those part as well. If you dont do this, the other clients wont be able to see the other players move in multiplayer mode.  

In the video tutorials, he tries to clean/organize his component dependency as much as he could, moving and removing photon components from multiple entities. I also did it, but it broke my simulation a day after the presentation and I couldnt solve the issue on time. 

Just add the Photon View transform to every game object you need to synchronize online.

ALSO VERY IMPORTANT


How to test multiplayer

Unfortunately, there is no easy way to test it. In the VR application case you need whether multiple HMDs. But if you only have one HMD, you can run an instance of your application from your computer and run another instance in your HMD. However, because your hardware limitations, only one instance is able to display in the VR headset and have access to the controllers input.

Test locally using Unity (Windows)