Page 1 of 1

OnJoinRoom firing multiple times

Posted: 23 Sep 2009, 22:01
by matrix211v1
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) {
      started = true;
      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.

Posted: 24 Sep 2009, 06:37
by ThomasLund
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



Posted: 24 Sep 2009, 16:43
by matrix211v1
You are a GOD!


Posted: 24 Sep 2009, 22:11
by ThomasLund
Super duper!!

Happy to help :-)