User variable doesn't update when changing rooms in Unity.

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

Moderators: Lapo, Bax

tropyw
Posts: 20
Joined: 23 Jul 2020, 16:52
Contact:

User variable doesn't update when changing rooms in Unity.

Postby tropyw » 10 Jul 2023, 13:35

Hey there,
I'm working on a project using Unity for the client side and Java for the server side. I'm having an issue with user variables when switching rooms.

Here's what's happening: if I'm in the same room as another user and they update a variable called "hold", everything works well. But when I change rooms, and that same user deletes their "hold" variable (sets it to null on the server), and then follows me into my new room, my client still shows that this user has the "hold" variable.

This issue doesn't seem to clear until I completely restart my Unity project. After a restart, the user is correctly shown as not having the "hold" variable. The strange thing is, the user who owned the "hold" variable can't see it in their client after they delete it, but if any user who left the room before the deletion comes back, they still see the deleted "hold" variable.

This is my code in my Unity project, so you can see I don't do anything strange:

Code: Select all

private void onUserEnterRoom(BaseEvent evt)
{
   User user = (User)evt.Params["user"];
   this._room.AddPlayer(user);
}

I'm using the user.GetVariable() to get the data.


And this is my server code when removing the hold variable:

Code: Select all

SFSUserVariable holdVar = new SFSUserVariable("hold", null);
holdVar.setNull();
this.getApi().setUserVariables(sfsUser, Arrays.asList(holdVar));


Hope you can help!
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 10 Jul 2023, 15:02

Hi,
can you specify which SFS2X version are you using and also the version of the Unity API?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
tropyw
Posts: 20
Joined: 23 Jul 2020, 16:52
Contact:

Re: User variable doesn't update when changing rooms in Unity.

Postby tropyw » 10 Jul 2023, 17:56

Unity api version: 1.8.1
SFS2X Server version: 2.14.0
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 11 Jul 2023, 07:08

Hi,
2.14.0 is pretty old. I would recommend to test the same scenario under the latest SFS2X 2.19.x and see if it can be reproduced.
You can install it in a local environment, add your Extensions (if any) and test there.
https://www.smartfoxserver.com/download ... =installer

Let us know
Lapo

--

gotoAndPlay()

...addicted to flash games
tropyw
Posts: 20
Joined: 23 Jul 2020, 16:52
Contact:

Re: User variable doesn't update when changing rooms in Unity.

Postby tropyw » 11 Jul 2023, 12:25

I have recently upgraded our SFS to the latest version (v2.19.2), yet the issue we've been experiencing persists. My assumption is that the client API isn't synchronizing properly with variables that have been removed from cached users while they are not in the same room. It appears to only update new or existing variables but doesn't eliminate the null ones when a previously interacted user joins a room.

Additionally, I'd appreciate it if you could consider providing us with the option to disable user caching in the client API. For instance, my game doesn't require previous user caching when leaving the room, and given that I'm using WebGL, minimizing memory usage is a key priority for me. :wink:

Thanks
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 12 Jul 2023, 09:01

It is possible that cacheing is involved in this.
We'll run a few tests to reproduce the use case and get back to you.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 13 Jul 2023, 13:44

We have tested the use case you have reported and did not find any issues with UserVariables, the variables that are removed outside of the Room never come back when the User joins the same Room or another one.

Here're the test steps:
- User A connects to a Lobby Room and waits
- User B joins the Lobby
- User B sets 3 room variables (X, Y, Z)
- User A receives update with the 3 UserVars
- User B leaves the Room
- User B deletes 2 of the three variables (X, Y)
- User A leaves the Lobby and joins the Garden room
- User B joins the Garden room
- User A correctly reports only one UserVar for UserB (Z)

Maybe there's something else going on in your client logic that is causing the problem, although I am not sure what could cause that.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
tropyw
Posts: 20
Joined: 23 Jul 2020, 16:52
Contact:

Re: User variable doesn't update when changing rooms in Unity.

Postby tropyw » 13 Jul 2023, 17:39

Lapo wrote:- User B sets 3 room variables (X, Y, Z)

I was not referring to the rooms variables; I was talking about the users variables. Additionally, I have now tested it using the Unity client API without incorporating any of my code, and the problem still persists. Therefore, now it's clear that the issue is not caused by my code.
Hope you can check it again.


tropyw wrote:Additionally, I'd appreciate it if you could consider providing us with the option to disable user caching in the client API. For instance, my game doesn't require previous user caching when leaving the room, and given that I'm using WebGL, minimizing memory usage is a key priority for me. :wink:

Also, in this statement, my reference is to the cached objects related to users, not to the ones related to rooms. If you can make such adjustments, that would be wonderful!

Thank you for all of your help! :)


--
Edit: Now I see you've wrote "UserVar" in one line after the "room var", and checked the var in another room, so i quess you did check it on user vars. In case you did, I'm curious, did you attempt to utilize User Variables through extensions or did you use the built-in method?

I've created a new Unity project and examined it with the latest client API. I wrote minimal code, but the issue still persists. Both the server logs and the admin tool indicate that the variable has been deleted. However, it seems like the client isn't reflecting this if the second user leaves before it's deleted.

Please try it this way:
- User A connects to a Lobby Room and waits
- User B joins the Lobby
- User B sets 3 user variables (X, Y, Z)
- User A receives update with the 3 UserVars
- User A leaves the Lobby and joins the Garden room
- User B deletes 2 of the three variables (X, Y)
- User B leaves the Lobby and joins the Garden room
Last edited by tropyw on 13 Jul 2023, 19:04, edited 3 times in total.
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 14 Jul 2023, 07:06

Yes, sorry I meant to write "User Variables", but I brainfarted :D
I've tested your sequence and was able to see the cached variables. So it really depends on order of joining, which is interesting.
We'll investigate this further and get back to you.

Thanks!
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 22961
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User variable doesn't update when changing rooms in Unity.

Postby Lapo » 14 Jul 2023, 10:08

Quick update: we should be able to send you an update for you to test, next week.
Please send us an email to our support@... email box and we'll notify you when the update is ready with the download.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 65 guests