You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the netcode Distributive Authority template in Unity 6000.0.25f1 to build for WebGL. In it, as in the documentation, asynchronous access to the Task CreateOrJoinSessionAsync(string SessionID, SessionOptions SessionOptions) method takes place the IMultiplayerService interface to connect to the session. After that, the result is written to the field for further asynchronous exit from the session: await _session.LeaveAsync();
I have not found any examples for WebGL, as well as detailed documentation on this topic. Since WebGL does not support Task, I have to convert Task to UniTask. When the method is first accessed, everything works fine, UniTask returns and the task is completed. But if you exit the session by calling await _session.LeaveAsync().AsUniTask(); then the CreateOrJoinSessionAsync method will no longer return UniTask. The method hangs on await. Despite this, the player will spawn on the stage. I checked the problem is in the CreateOrJoinSessionAsync method. All other operations are completed correctly. I also initialized services on Start using await Unity Services.InitializeAsync().AsUniTask(); Below is the code. Please help me understand how to work with this in WebGL:
private ISession _session;
public async UniTask StartDisconnectAsync()
{
if (_session != null)
{
await _session.LeaveAsync().AsUniTask();
Debug.Log($"SessionState {_session.State}");
}
State = ConnectionState.Disconnected;
}
public async UniTask CreateOrJoinSessionAsync(string sessionName, string playerName)
{
State = ConnectionState.Connecting;
try
{
if (!AuthenticationService.Instance.IsSignedIn)
{
AuthenticationService.Instance.SwitchProfile(playerName);
await AuthenticationService.Instance.SignInAnonymouslyAsync().AsUniTask();
}
var options = new SessionOptions()
{
Name = sessionName,
MaxPlayers = _maxPlayers
}.WithDistributedAuthorityNetwork();
_session = await MultiplayerService.Instance.CreateOrJoinSessionAsync(sessionName, options)
.AsUniTask();
State = ConnectionState.Connected;
}
catch (Exception e)
{
State = ConnectionState.Disconnected;
Debug.LogError($" {e}. Task failed.");
}
}
Reproduce Steps
Let's call the CreateOrJoinSessionAsync() method. The unitask will complete correctly. The session will start and the player will spawn on the stage.
Let's call the StartDisconnectAsync() method. The player will leave the session.
Let's call the CreateorCreateOrJoinSessionAsync() method again. The player will be spawned, but the task will not be completed.
Environment
Google Chrome, Yandex browser
Unity Version: 6000.0.25f1
Multiplayer Services 1.0.2, 1.1.0
Netcode Version: 2.1.1
The text was updated successfully, but these errors were encountered:
NikitaUstinov092
changed the title
There is a problem with calling MultiplayerService.Instance.CreateOrJoinSessionAsync in the WebGL build
There is a problem with calling MultiplayerService.Instance.CreateOrJoinSessionAsync in the WebGL build [Distributive Authority]
Dec 19, 2024
Description
I use the netcode Distributive Authority template in Unity 6000.0.25f1 to build for WebGL. In it, as in the documentation, asynchronous access to the Task CreateOrJoinSessionAsync(string SessionID, SessionOptions SessionOptions) method takes place the IMultiplayerService interface to connect to the session. After that, the result is written to the field for further asynchronous exit from the session: await _session.LeaveAsync();
I have not found any examples for WebGL, as well as detailed documentation on this topic. Since WebGL does not support Task, I have to convert Task to UniTask. When the method is first accessed, everything works fine, UniTask returns and the task is completed. But if you exit the session by calling await _session.LeaveAsync().AsUniTask(); then the CreateOrJoinSessionAsync method will no longer return UniTask. The method hangs on await. Despite this, the player will spawn on the stage. I checked the problem is in the CreateOrJoinSessionAsync method. All other operations are completed correctly. I also initialized services on Start using await Unity Services.InitializeAsync().AsUniTask(); Below is the code. Please help me understand how to work with this in WebGL:
Reproduce Steps
Environment
The text was updated successfully, but these errors were encountered: