Strange problem with RPC

marf
marf
Hi, I'm making an online fps, at the moment I'm scripting the team assignment.

When I istantiate a player I call this code:
GameObject player = PhotonNetwork.Instantiate(playerPrefab, spawnPointAlpha.position, Quaternion.identity, 0) as GameObject;
player.GetComponent<PhotonView>().RPC("SetTeam", PhotonTargets.All, "BravoTeam");

The RPC is this:

void SetTeam(string TeamName)
{
Debug.Log("SetTeam RPC e TeamName: " + TeamName);
gameObject.GetComponent<ThirdPersonNetwork>().team = TeamName;


}


The scripts works well if host the room with the editor (all players have his own team names), but if I host the room with a compiled client one of the two players team is blank.

I use Debug.Log("SetTeam RPC e TeamName: " + TeamName); when the editor host a match this is called two times (for the two players), when a client host a match this is called only one time.

I don't know why the player that host the match have blank team if this is the client.

Thanks a lot,

Marco

Comments

  • Try to debug this with MonoDevelop or at least check the log files. Maybe it's some exception?
    There should be no difference between editor and player and I have to admit, that I didn't fully understand how I could help you.
  • If I don't use OnGUI function with Buttons and so on, this work, I don't know why...
  • OnGUI is called many times per frame, that might have an impact.

    Also ongui is a 'special function' in general, there are other things known to throw up if used from OnGUI due to how it works.

    Its generally better to set a boolean state variable in OnGUI and let Update / LateUpdate / FixedUpdate or a yielding coroutine take over the handling and processing of the data. (basically do a MVC seperation with OnGUI only being the View, not View + Controller)
  • Yeah, I do that...

    I've attached the scripts of ThirdPersonNetwork and GameManager (I used the Viking Demo Scripts as base).

    I want only to know by community if all this has a correct logic, because I have a lot of problems with addDamage and respawn, too, in fact this works if someone shoot to the other player only if he's the editor.

    I don't post PlayerScripts.cs there there is only the life count.