I am trying to implement multi-player networking with Photon PUN 2 in a Unity game. I have only been looking at this for two days, so I am learning as I go. Sorry for the long question:
I have managed connection, the lobby, creation / joining rooms etc, and am moving on to transfer of real time information during the game play. Where I am stuck due to not understanding the concepts well enough.
It is a very simple test game: some cubes that tumble around a square field - just to check concepts.
Conceptually, there are two types of player - 'my player', and 'other player(s)'. I control the movement of 'my player', and I want some information as to what any 'other players' are up to - however I do not necessarily want 'other player' positions and state etc just to be replicated in my (local) room - I want some information as to what they are up to, then I'll decide what to do with the information.
At start up time in the game play scene, I read the list of players in the room and for all that are not me (ie Player.IsLocal is not set - so not 'my player'), instantiate an 'other player' from a prefab.
'My Player' and 'other player' are really quite different types of object - the first moves around, the other just stores some information about what the remote 'other player' is up to.
Firstly, because of the above, although part of what I want is the 'other player' position, I do not want to use PhotonTransformView - I just want to get the positional (and other) information and know which 'other player' it came from. However when I attached a PhotonView to my local 'other player' copy and then set 'other player' as the observable object, the editor immediately stuck in a PhotonTransformView as well saying I needed that to replicate position. Well, I don't, but as soon as I removed the PhotonTransformView, it removed the observable reference as well! It appears if the object has a transform, it is going to get a PhotonTransformView whether it likes it or not.
- Question 1 - how to I stop that?
Next, bowing to the inevitable, I put a PhotonView and PhotonTransformView on both 'my player' and 'other player' to see what happened. Well, I found that what happened was that as I moved 'my player' around, the 'my player' in the remote scene moved around - the 'other player' didn't move at all. From that I conclude that information appears only to be transferred between two objects of the same type? Ie local 'other player' information goes only to remote 'other players', ditto 'my player'. So
- Question 2 - how to I transfer information from object type A in the local scene to object type B in a remote scene?
I suppose what I really want to do is this: in the local scene I want to send out a package of information identified as from me (presumably by ActorNumber). I also want to receive packages of information from remote scene(s), in each case also identified by Actor Number, and having got them, I can decide what to do with them. I do not really want automatic transfer of any specific piece of information. I gather IPunObservable is the relevant interface to support, so really, what I want is a
free standing script implementing IPunObservable in which I cam use OnPhotonSerializeView() to read and write the information. Not sure how - to have a freestanding script, I appear to need a GameObject to attach it to, GameObjects have Transform components that it appears you cannot remove, so I'll be back forced to use PhotonTransformView. So
- Question 3 - can I do that, if so, how?
I am not really concerned whether one thinks what I am trying to do is sensible or not - this is really just a learning exercise to find out how the architecture works and what it allows. Once I have figured that out, then I can decide on real implementation. But - first comes the knowledge.
So, on that basis, any explanatory help gratefully received!
See Question&Answers more detail:
os