Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats PSDK not refreshing when stats are set server-side #3836

Open
allister-beamable opened this issue Dec 19, 2024 · 1 comment
Open

Stats PSDK not refreshing when stats are set server-side #3836

allister-beamable opened this issue Dec 19, 2024 · 1 comment
Milestone

Comments

@allister-beamable
Copy link
Contributor

Describe the Bug

When I do await ctx.Stats.Refresh(); before interacting with the Stats collection, I expect the stats to reflect the latest and greatest values of those stats, but if the stat were changed server-side, the Stats collection contains stale data until I stop and start the app.

To Reproduce

Steps to reproduce the behavior:

  1. Set a stat to a certain value.
  2. Iterate over the Stats collection to print the value.
  3. Use C#MS code to change the stat from step 1 to a different value.
  4. Call Stats.Refresh() and iterate over the collection to print values again.
  5. Observe the value of the stat.

Expected Behavior

  • The value in the Stats collection should reflect the change from step 3 of the repro steps.

Actual Behavior

  • The value in the Stats collection shows the old value from step 1 of the repro steps.

Sample Code

Client Code

These calls are hooked to buttons in my test harness.

private async Task SetRandomStat()
{
	var client = new BoxMicroserviceClient();
	var theNumber = await client.SetNumericStat();
	Debug.Log($"Numeric stat setting completed: {theNumber}");
}

private async Task FetchStats()
{
	var ctx = await BeamContext.Default.Instance;
	await ctx.Stats.OnReady;

	Clear();
	Debug.Log("Reading current stats...");
	await ctx.Stats.Refresh();
	foreach (var statPair in ctx.Stats)
	{
		Debug.Log($"S: {statPair.Key}={statPair.Value}");
	}
}

Server Code

[ClientCallable, SwaggerCategory("StatsTests")]
public async Task<int> SetNumericStat()
{
	var objectId = $"client.public.player.{Context.UserId}";
	var theNumber = Randomizer.Next();
	var statsRequest = new NumericStatsUpdateRequest
	{
		set =
		{
			["NUMERIC_SOMETHING"] = theNumber
		}
	};
	var uri = $"/object/stats/{objectId}";
	var response = await Requester.Request(Method.POST, uri, statsRequest, parser: s => s);
	Debug.Log($"RESPONSE: {response}");
	return theNumber;
}

Screenshots

Screenshot 2024-12-19 at 17 33 43

Metadata

  • SDK version: Beamable Unity SDK 1.19.23
  • Engine version: Unity 2021.3.27f1
  • Operating System: macOS

Additional Context

The new value is reflected properly if the app is closed and reopened.

@cdhanna
Copy link
Collaborator

cdhanna commented Jan 8, 2025

My hunch is that the Stats API is hitting its own cache when we ask to refresh. Check out the PlayerStats class.

@cdhanna cdhanna added this to the Unity 2.1.1 milestone Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants