Photon Instantiate Hold

Hi there,

I have a little question/request for a clue in the next matter.
I'm making a small TPS, and have a player prefab and all, players can perform actions like changing weapons and what not, that are sending RPCs to the other clients.

The thing is this, I have a player list, that the client recieves when he joins the room, but until then, Photon.Instantiate, creates the other clients in the game. If a player sends an RPC that requires information to be present in my clients player list, I get a null reference error. (I didn't get the updated player list after I joined yet).

My question is, can I avoid this with an elegant solution? As at the moment I have a bool, that becomes true once I recieve the player list, but I dont want to put it in every relevant RPC to avoid errors.

Maybe there's a way to hold Photon.Instantiate back, until a certain condition is met?

Thanks ahead,
Michael.

Comments

  • The player list should be setup for you when you get the on-joined callback. Any Instantiate calls done in the room (before you joined) will then follow, mixed with any buffered RPCs you did. Only then the first "live" events will happen.
    You could store the loadout of a player in the player properties. Then you don't need RPCs for it and you get it on join, too. Just use player.SetProperties.
  • You're talking about the built in player list, and player properties?... Well, idk, that'd take some rewriting to do, I use a custom playre class with alot of information in it, and my player list is a list of these custom classes. That's why I use an RPC.

    Is there a way to shove the custom class as a property into the player properties?

    EDIT: I realized that I convert my player information to strings to send them over to the other players, so I just shove it into a slot of customproperties, but now I have another question:

    I take all the player information from the PhotonNetwork.playerList, then loop foreach PhotonPlayer, and get the customProperties var for the info, and it seems to work, but when I try to do, PhotonPlayer.Find(id), using the id I got from the customProperties, I get a null. As if I have the PhotonNetwork.playerList, but The PhotonPlayer.Find can't find a specific player...

    How can I fix that? and why would it not find the player if I clearly have him in the PhotonNetwork.playerList?
  • You should be able to find a player by Player.ID. It seems you're not using those IDs at the moment?

    For serialization: Don't use strings when you want to store numbers. Using Bytes and Integers for those will be leaner in a network-traffic way and that in turn makes it more likely things work nicely on other machines and worse net conditions.
  • I was trying to find the photonplayer by player.id, it was a problem on my end though, as I made the change to use the customproperties, I was looking for a good place to set them, so that it won't be late, and won't be too early either.

    I found out that I was setting it too early, and I was getting the id of -1 for the master client (I was testing if I joined right after the master client, less than a second apart). In the end I managed to set it correctly, and let the new player wait before getting the information if there's someone with an id of -1 in the customproperties.

    Now it seems to work correctly.

    Thanks!