SFS2X callbacks won't get called after LoadLevel()

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

berry
Posts: 11
Joined: 06 Sep 2010, 09:53

SFS2X callbacks won't get called after LoadLevel()

Postby berry » 08 Sep 2010, 11:59

Hi,

I'm working on a Unity project and I'm very excited to see that you've chosen a AS3.0-like approach (which is the programming language I'm coming from) for the UnityClient API.

In Unity I've made a login scene with a GUI and a script, in which the connection with SmartFox seems to work like a charm. The only problem is when I switch to a new game scene by calling Application.LoadLevel("gameScene") with it's own script I no longer seem to be able to add eventlisteners to the smartfox object ( or at least the callbacks in this new script won't get called).

I'm referencing the smartfox object in both scripts via a static instance in a SmartFoxHolder class, very much like in the examples. Somehow the requests do reach the server. It's just that the callbacks aren't excecuting after the requests have been send.

EDIT: I did use the RemoveAllEventListeners() on the smartfox object right before loading the new scene, and tried reassigning them in the new scene. After this reassigning-part is where things go silent.

Any help on the situation would be much appreciated.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Sep 2010, 19:55

Super weird.

Do the example 3 work for you otherwise? It also uses multiple scenes that get loaded as well as standard LoadLevel()

/Thomas
berry
Posts: 11
Joined: 06 Sep 2010, 09:53

Postby berry » 10 Sep 2010, 07:54

Boy, oh boy.. do I feel stupid now. :oops:

The ActionScript-like namingconvention which I like so much, got me on this one. It was just a silly typo on the FixedUpdate call for Unity. Since I named it OnFixedUpdate, the smartfox.ProcessEvents() wouldn't get called in the gameScene. Both me and one of my colleagues completely missed it on the error-tracking.

Fixed it now. Thanks for the reply anyway.
:)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 10 Sep 2010, 08:24

Ahhhh - super!! You had me worried for a few seconds :-D

But yeah - the requirement of the fixed update can be tricky to spot. Got any good ideas on how to make it more obvious? (I dont)

Especially if you are also using Unity 3, the thread safety will simply force you to use this way to empty the response queue - else you game crashes hard. Thats why I made it default mode in the new API

Shoot away with questions if you run into anything else - anything at all

/Thomas

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 69 guests