Player instantiation BY MAGIC!?!
Options
Dave_A
✭
I've got a little game I'm building, using the Photon Asteroid example as a model. that is, it has a 'lobby' where players gather, then enter the main scene. When I load the main scene I instantiate player avatars. I must be doing something wrong, but it's spooky what happens:
I'm assuming I'm only going to instantiate my avatar when it's 'local' (that's 'me' right?). In fact, I maybe don't even need to see 'me' so I could avoid this?
Well here's the spooky part. If I join one player from remote, I have 2 players when I enter this scene. One isLocal, the other is not. So, only ONE (the local one) should be created, yes? BUT TWO are created. And I cannot figure out where it's coming from. This is the only place in the game I reference playerPrefab, and it's in my class (unless it's hiding a same-named object in a base class???) Anyway, the code that sets the name and avatar label does NOT get executed on the remote user. Everything else about the remote player works fine, I can see him moving properly about the scene.
Any insights welcome.
Edit: Probably PhotonNetwork.Instantiate is creating this phantom. How do I set properties on that? Is there an 'on object instantiated' callback? Or with PlayerCustomProperties?
Player[] sorted = PhotonNetwork.PlayerList.OrderBy((p) => p.ActorNumber).ToArray(); Debug.Log(sorted.Length + " users in room"); foreach (Player p in sorted) { Debug.Log(string.Format("{0} {1}: is local {2}, is masterclient {3}, ", p.NickName, p.UserId, p.IsLocal, p.IsMasterClient)); if (p.IsLocal) { GameObject go = PhotonNetwork.Instantiate(playerPrefab.name, Camera.main.transform.position, Quaternion.identity, 0); go.transform.parent = Camera.main.transform; go.name = p.NickName; go.SendMessage("SetAvatarName", p.NickName); ; } }
I'm assuming I'm only going to instantiate my avatar when it's 'local' (that's 'me' right?). In fact, I maybe don't even need to see 'me' so I could avoid this?
Well here's the spooky part. If I join one player from remote, I have 2 players when I enter this scene. One isLocal, the other is not. So, only ONE (the local one) should be created, yes? BUT TWO are created. And I cannot figure out where it's coming from. This is the only place in the game I reference playerPrefab, and it's in my class (unless it's hiding a same-named object in a base class???) Anyway, the code that sets the name and avatar label does NOT get executed on the remote user. Everything else about the remote player works fine, I can see him moving properly about the scene.
Any insights welcome.
Edit: Probably PhotonNetwork.Instantiate is creating this phantom. How do I set properties on that? Is there an 'on object instantiated' callback? Or with PlayerCustomProperties?
0