Noob Question

Hey,

I just started diving into the complicated world of networking and Photon came highly recommended, so I started using it.

So first of all, I'm at the point in the PDF tutorial that has this set of code:
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{ 
if (stream.isWriting) { //We own this player: send the others our data stream.SendNext((int)controllerScript._characterState);          stream.SendNext(transform.position); stream.SendNext(transform.rotation); 
} 
else 
{ //Network player, receive data controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
} 
}

My first question, is what is controllerScript and _characterState. I thought _characterState was of CharacterState (like in the receiving end), but I can't figure out what connects controllerscript to _characterstate. Also, what purpose does this line have. Is it for animation?

Second, and more importantly, this whole function isn't getting called at all in my script. I set debug code in the if, else, and outside both and none get called. I have PhotonViews attached to the cube in my owner client and the joined client, with the correct gameobject observed, that update properly (I move it around in owner, it moves it in joiner). I assumed this method gets called whenever the PhotonView observed gameobject is moved/rotated, but it isn't being called. Why is that?

Third. How do I get an object in the joined client to own something using the above method so it can move it around and the owner client can get the updates? I see the point of having certain things only the owner can control, like lobby options, but I also assumed this would be used for Player information. If so, then it would be necessary for non-owner clients to be able to send their info to the owner and have it update. Or maybe this is better used with RPCs, I haven't gotten that far yet, so I have no idea. I'm just trying to fully grasp these things one at a time as to not get overwhelmed.

Thanks for the help and sorry if the answers are super obvious and I should've seen them heh.

Comments

  • Darknuke wrote:
    My first question, is what is controllerScript and _characterState. I thought _characterState was of CharacterState (like in the receiving end), but I can't figure out what connects controllerscript to _characterstate. Also, what purpose does this line have. Is it for animation?

    Probably something like this, since it's cast to int. It's just illustrating that you can serialize your own custom stuff too, not just Vector3, Quaternion, etc.
    public enum CharacterState
    {
    	None,
    	Eat,
    	Sleep,
    	Quest,
    	Fight	
    }
    
    I can't answer your other questions though, I'm newb myself.
  • My first question, is what is controllerScript and _characterState. I thought _characterState was of CharacterState (like in the receiving end), but I can't figure out what connects controllerscript to _characterstate. Also, what purpose does this line have. Is it for animation?

    This script is from the file ThirdPersonNetwork. It's observed by the PhotonView of a Player prefab and used to send a local player's updates to others and apply incoming changes from remote players.
    The state of a char is of Type CharacterState (a enum, which can be cast to int). Each player's state is stored in _characterState. It's sent in intervals (when the script is called with streadm.isWriting) and updates from others are applied to local "copies" when the stream is for reading.

    > Second, and more importantly, this whole function isn't getting called at all in my script.
    You need to attach the script AND a PhotonView to a prefab. Then assign the script to the PhotonView's "observed" field by drag and drop. This is the default as long as you didn't change the Worker Demo. The script ONLY gets called when it's observed by some PhotonView. PhotonView's can alternatively observe the Translation of their object directly (without script).

    I think I didn't get the third question really. Maybe you can check the help above and then rephrase the question?
  • I got to this part of the documentation, and there isn't a lot of information on it, and trying to come across some is making my head spin. I'm trying to follow this documentation and set up a small room where players can see each other in first person. I'm trying to base this off of the first person input controller.

    I'm just at a blank here, I don't understand what the controllerScript is, or anything on the characterState. *Bangs head against table*
  • I think you're better off with the Marco Polo tutorial you are reading. It shows what's needed to setup a cam and what's the difference when you do it for multiplayer (fight for control).
    Don't give up!