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

There is a problem with calling MultiplayerService.Instance.CreateOrJoinSessionAsync in the WebGL build [Distributive Authority] #3182

Open
NikitaUstinov092 opened this issue Dec 19, 2024 · 0 comments
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report

Comments

@NikitaUstinov092
Copy link

NikitaUstinov092 commented 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:

   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

  1. Let's call the CreateOrJoinSessionAsync() method. The unitask will complete correctly. The session will start and the player will spawn on the stage.
  2. Let's call the StartDisconnectAsync() method. The player will leave the session.
  3. 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
@NikitaUstinov092 NikitaUstinov092 added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Dec 19, 2024
@NikitaUstinov092 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

1 participant