OnJoinRoom firing multiple times

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

Moderators: Lapo, Bax

matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

OnJoinRoom firing multiple times

Postby matrix211v1 » 23 Sep 2009, 22:01

Ok, here is my issue. I have created each scene to be a room. When a user moves from one room to another, I call LeaveRoom then I load the new scene. Each scene has it's own "NetworkController" where I got the example from the SFSIsland Demo. There is NO DontDestroyOnLoad in any code. Each scene has it's own Prefab of the "NetworkController".

In the Start function of the NetworkController.cs, I have this:

Code: Select all

   void Start() {
      Debug.Log("NetworkController: Start");
      Application.runInBackground = true; // Let the application be running whyle the window is not active.
      smartFoxClient = GetClient();
      if (smartFoxClient==null) {
         Application.LoadLevel("LoginScreen");
         return;
      }   
      SubscribeEvents();
      started = true;
      smartFoxClient.JoinRoom(Application.loadedLevelName);
      Debug.Log("NetworkController: Finish");
   }


And it works wonderful the first time I enter the room. I see all the other players, everything is fine.

Now, I go to a new scene from within the game. As I mentioned, I call "LeaveRoom" and I load the new scene.

This is the problem: OnJoinRoom will fire 2 times. If I go into another scene, it will fire 3 times, another scene, it will fire 4 times and so on for however many scenes I try and connect within the game.

It's almost like there is a counter following it. I have NO CLUE where to start looking to track this down. I thought to look into the ProcessEventQueue and maybe clear it out or something when a new scene is loaded but I don't even understand it's purpose let alone how to clear it out.

Any thoughts? I can provide the 2 scripts if anyone wants to look at them (the 2 scripts are the NetworkController and PlayerSpawnController from the SFSIslandDemo).

Thanks in advance.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 24 Sep 2009, 06:37

I do have an idea, yes.

Before you switch scene - do you unregister your code from the SFSEvent? If you look at the tutorial code, on scenechange I always remove the delegate from SFSEvent before going into the new scene where I then register again.

That would be my best off-the-bat guess to what is going on

/Thomas
matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

You

Postby matrix211v1 » 24 Sep 2009, 16:43

You are a GOD!

Thanks!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 24 Sep 2009, 22:11

Super duper!!

Happy to help :-)

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 18 guests