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

Pubsub example not working with Release 1.0.5, hangs when calling .Connect() #73

Open
Nights87 opened this issue Jan 10, 2024 · 1 comment

Comments

@Nights87
Copy link

Nights87 commented Jan 10, 2024

Upon running the line _pubSub.Connect(); unity just hangs and I have to kill the editor. Running 2023.2.4f1 with HDRP pipeline.

Is there anything I need to add/do?

Code is same as the sample, but ill post anyway

private void Start()
{
  // Create new instance of PubSub Client
  _pubSub = new PubSub();
  
  // Subscribe to Events
  _pubSub.OnWhisper += OnWhisper;
  _pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
  
  // Connect - hangs when running this
  _pubSub.Connect();
}
@ffortat
Copy link

ffortat commented Apr 27, 2024

I had the same issue, it appears all network related methods in TwitchLib.PubSub has been updated to use Async methods (see this commit)

From what I've found, running async code on Unity's main thread freezes it, you have to wrap it in a Task.Run(...) so you can change your snippet to this:

private void Start()
{
  // Create new instance of PubSub Client
  _pubSub = new PubSub();
  
  // Subscribe to Events
  _pubSub.OnWhisper += OnWhisper;
  _pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
  
  // Connect - hangs when running this
  Task.Run(async() => await _pubSub.ConnectAsync());
}

This way it shouldn't hang. The same goes for all the methods that now have an Async variant.

I don't know if it's the best way to go, it would be nice to update this lib to have a helper to run in coroutines for example, but this works for now.

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