Unity: Changing Scene when changing room. Best practices.

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Unity: Changing Scene when changing room. Best practices.

Postby LordDawn » 29 Apr 2019, 10:20

Are there any best practices for changing scene in Unity whilst connected to SmartFox?

I have my SmartFox on a separate DoNotDestroy object, so is Scene independent. Now I want to change scene when an JOIN_ROOM message comes along. Obviously there will be some duration to the scene change whilst maps etc are loaded, so I wondered if there are any best-practices for dealing with this changing scene duration and handling any messages that arrive during the scene change.

I'm using MMORooms if that makes a difference, and the User will only be in one room at a time.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity: Changing Scene when changing room. Best practices.

Postby Lapo » 29 Apr 2019, 14:46

Hi,
it depends on the game itself and what can happen while a new game level/scene is being loaded.
If you need to wait for the scene to be loaded before responding to new SFS2X events, if may need to either store those event in a queue or stop polling the API's own event queue until you're ready.

Makes sense?

I'm using MMORooms if that makes a difference, and the User will only be in one room at a time

There is no particular difference with using MMORooms.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Re: Unity: Changing Scene when changing room. Best practices.

Postby LordDawn » 29 Apr 2019, 15:53

Ahh, thanks Lapo. I hadn't thought of stopping polling. Though I don't think that'll be perfect for my case. I did think about storing some of the incoming events, but was unsure of the life-cycle of events, and if they could be queued, and at what point they are destroyed.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity: Changing Scene when changing room. Best practices.

Postby Lapo » 29 Apr 2019, 16:47

Events are mostly just notifications... they tell you about something that just happened.
For instance when Room Variables are updated the client receives them, stores them locally and then tells you about it. So technically the data is already updated, even if you delay the event processing.

There may be side effects to delaying the processing though, in certain cases.
Imagine you get 3 Room Var updates in a row.
1) Var x = 10
2) Var x = 30
3) Var x = 50

If you react to these updates as they come you will get each value as they get notified.
If you delay the processing you will just get the x = 50 for all three events as the last update overwrote the previous states.

Most of the times I'd say this is not an issue, because you want to deal with the most up to date value anyways.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Re: Unity: Changing Scene when changing room. Best practices.

Postby LordDawn » 29 Apr 2019, 17:40

That's very helpful, Lapo, thank you.

I'll go and spend the evening with a pen and paper, and work out the best architecture now I have good data to work with.
User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Re: Unity: Changing Scene when changing room. Best practices.

Postby LordDawn » 29 Apr 2019, 20:13

One more question on the subject.

If I stop calling the ProcessEvents() are incoming events queued until ProcessEvents() is called again (may be up to 20 seconds of no calling) and then processed in the order they were received, or are incoming events during this time lost forever?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity: Changing Scene when changing room. Best practices.

Postby Lapo » 30 Apr 2019, 07:11

LordDawn wrote:If I stop calling the ProcessEvents() are incoming events queued until ProcessEvents() is called again (may be up to 20 seconds of no calling) and then processed in the order they were received, or are incoming events during this time lost forever?

If you stop processing them they will just pile up in the queue. So nothing is lost.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Re: Unity: Changing Scene when changing room. Best practices.

Postby LordDawn » 30 Apr 2019, 07:24

Thanks Lapo, this is all useful info. Helps me nail down all the edge scenarios, so I don't code mistakes in from the outset (well, no more than usual).

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 21 guests