Bug in PlayerSpawnController.cs from SFSIslandDemo?

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

COB
Posts: 68
Joined: 28 Dec 2010, 08:54

Bug in PlayerSpawnController.cs from SFSIslandDemo?

Postby COB » 28 Dec 2010, 09:09

I think that there may be a bug in this example which manifests itself in spawning each remote player twice.

I have added some comments to the sample code:

Code: Select all

private void UserEnterRoom(User user) {
   //When remote user enters our room we spawn his object.
   SpawnRemotePlayer(user); //first spawn
   remoteUser = user; //remoteUser becomes !=null
}

private User remoteUser = null;
void FixedUpdate() {
   if (remoteUser!=null) {
      SpawnRemotePlayer(remoteUser); //second spawn because remoteUser!=null
      remoteUser = null;   
   }
}

Is it a bug? For me it works better when I remove the whole FixedUpdate() function. I am a novice when it comes to the Unity and SFS, so it may be only a my mistake, but I would like to get your opinion.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 28 Dec 2010, 10:21

I don't know where you got that code but it surely didn't come from the Island demo.
The spawning has never been in FixedUpdate.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 28 Dec 2010, 10:24

appels wrote:I don't know where you got that code but it surely didn't come from the Island demo.
The spawning has never been in FixedUpdate.



Oops you are right, it's in the playerspawn script.
That's been in there since the beginning and works perfctly.
You will have a problem somewhere else in your code.
COB
Posts: 68
Joined: 28 Dec 2010, 08:54

Postby COB » 28 Dec 2010, 10:50

You are right. It works, but in "Hierarchy" window I see two remote player objects with the same number spawned each time someone joins the room. Can someone check this?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 28 Dec 2010, 12:34

in the spawnremote you should also have :
if(!GameObject.Find("remote_"+user.GetId())) {

so it doesn't spawn it twice.
COB
Posts: 68
Joined: 28 Dec 2010, 08:54

Postby COB » 28 Dec 2010, 13:00

Unfortunately original SpawnRemotePlayer(User user) looks like this:

Code: Select all

private void SpawnRemotePlayer(User user) {
   // Just spawn remote player at a very remote point
   UnityEngine.Object remotePlayer = Instantiate(remotePlayerPrefab, new Vector3(-10000, -10000, -10000), new Quaternion(0,0,0,1));
   
   //Give remote player a name like "remote_<id>" to easily find him then
   remotePlayer.name = "remote_"+user.GetId();
   
   //Start receiving trasnform synchronization messages
   (remotePlayer as Component).SendMessage("StartReceiving");
         
   // Force this player to send us transform
   ForceRemotePlayerToSendTransform(user);
}

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 26 guests