I'm completely new to photon. I have a fair bit of experience with Unity but learning multiplayer feels like learning a new game engine lol.

I'm using photon and making a chess game, so I've put photon Views and practically everything, except the objects I want to be unique. I feel like I've gotten most of it figured out, but for some reason, when I start a multiplayer game, it doesn't initialize my chess pieces properly. So, I have it placing all the pieces at start, here is my pastebin for reference, the InitiateBoard() method is what's having issues, starting at line 85, the error is at line 100.


The "pieces" array is a 2D array of the ChessPiece class, which assigns the sprites, team, and movesets based on position on the board. It's very strange, it works just fine on a single player game, but if I build the game and play two player(which is the exact same script, it just disables the AI), for some reason, only the build gets a null reference exception error at this line,

pieces[x, y] = spawnedPiece.GetComponent();

It seems to be unable to get a reference to the chesspiece, and therefore, it sets all the pieces to white rooks as white rook is in the default position. Weirdly, the pieces initialize properly on the editor's screen. And also, if I play the build version in single player, it seems to initialize everything just fine.

After some testing, I realized it's only the joined player that is having issues, I tried running the build version first, then joining through the editor, it does the exact same bug with the same error code on the editor rather than the build version. So I can look at the editor and see a bunch of white rooks, but when I look at the build, it will be a bunch of properly assigned pieces... And yes, I am certain they are in the same game, as it calls an RPC to start the game and if I move one piece, I can see said piece is moved on both games.

Does anyone know what could be causing this? It's spawning the pieces just fine, but it doesn't seem to be able to get the component on the spawned piece...

  • \$\begingroup\$ Please boil this down to a Minimal Complete Verifiable Example, so that the code we need to look at fits inside the question itself, rather than in an external link. \$\endgroup\$
    – DMGregory
    Mar 22 '21 at 10:28

You must log in to answer this question.

Browse other questions tagged .