ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
The explosions pool objects were 0 for the client. Back to select multiple character tutorial. I had to spawn the players in. In the tutorial, their way was to spawn player prefab(s) from the resources folder. I also spawn the player prefab from the resources folder, but only the sprite changes. I am having trouble syncing the sprites. I decided to use RPCs (Remote Procedure Calls) ChangeAvatar() function has a [PunRPC] attribute. I check if the player is myself and then update the sprite based on if it's the master or client. If the player never selected an avatar and pressed play, then set the sprite default to index 0 I made sure to assign the body and bodysprites(in the same order from lobby) so that there are sprites to select from. However, after doing all this, only the local player was changed. The other player could not see the actual sprite the other user has After researching around, it seems like my RPC function should have been working. So I decided to spawn ONE test prefab instead of two player prefab. This test prefab has PhotoView and has code that when I press "I" key, the RPC function will be called to change sprites. With this test, the RPC function appears to be working because when I press "I" in the editor to change sprites, I can see the sprite changing on the mobile. This tells me something is going on with the Player Prefab and my understanding of RPC is wrong When I added if(view.IsMine) in the testScript to spawn the test Prefab around the code in the RPC function, the changes gets applied only to the local one. So I decided to spawn only 1 player - whoever is the master. Then Get rid of view.IsMine check. However, calling the RPC function still has view.IsMine check. Then if it is the master client, assign a yellow sprite otherwise a green sprite. It turns out the RPC function is being called properly, but because I am checking the host or client, it will assign the sprite to the player(s). So I should be doing another check, maybe check the target player? Similar to how in LobbyManager I check if Local player is the target player then apply LocalChanges After multiple builds, I finally figured it out! I did have to use a similar approach of checking Photon.Realtime.Player with PhotonNetwork.LocalPlayer. Like the PlayerItem in lobby, I assign a variable to the Instantiate function then call SetPlayerInfo which I defined in Player script and pass in the Photon.Realtime.Player The SetPlayerInfo assigns the Photon.Realtime.Player that's passed in to the local Photon.Realtime.Player. Then I call UpdatePlayerItem(), passing in the player. UpdatePlayerItem() checks if it is itself then calls a RPC function The RPC function checks if the Photon.Realtime.Player contains the PlayerAvatar key. This will exist if the user pressed the arrow button in the lobby. If yes, assign the sprite (which is in a bodySprites array on the Player script). If the arrow button was not pressed, then the sprite is just the first one so index 0 of the bodysprite array As shown in the result below, the body that both player chooses gets synched across the network in the game This blog is getting long, I should probably start a new page. Part 5 can be found here