-
Notifications
You must be signed in to change notification settings - Fork 428
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
TrySetSetString can only be called from the main thread. #261
Comments
Hi @ColorTwist, Sorry about the confusion, this has become an issue with newer versions of Unity that we did not originally plan for, as previously the ContinueWith would typically occur on the main thread as well. While we are looking into better support for handling this, something you can do in the meantime is set it up to execute on the main thread yourself. Unfortunately Unity doesn't provide a built in way to do this, but you can set up a method yourself, to queue up Actions that can then be executed during a MonoBehaviour's Update call, which will be on the Unity main thread. If that doesn't make sense, I can provide an example if you need one. |
Thanks for the reply. |
Yeah, no worries. So, to just provide you with what we do with our libraries, we have a class that to queue up actions, and provides a method to run on the owning thread. Note that you probably would not normally need something this complex, but for a general solution that handles a lot of cases, this should work.
In order to use that class, in a MonoBehaviour you would do:
And then finally, you could use that with your Auth call like:
As for |
Thanks for the example! Appreciated 👍 |
@a-maurice Thanks for providing this workaround. I'm still a bit confused as to how to use it correctly. As in, what should the signature be of methods passed into RunOnMainThread? I'm getting an ambiguous type error and not really sure where to go from here, being pretty new to threading and all. Any help is appreciated. |
@a-maurice , I too am having some issues getting this working. I have created the script above, and added the code to the MonoBehavior that contains the ContinueWith. Then in the ContinueWith, I have
I added the cast because I was getting a conversion error. But I am still getting the error "The type arguments for method 'AuthManager.RunOnMainThread(Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly." Any thoughts on what I need to do here? Thanks! |
Hi @robertlair Sorry for the delay in response. Not entirely sure what that error could mean, unfortunately. My best guess would be that the type of HandleAction isn't the correct type for it. Basically, you would want to be calling it with something like: |
I am using the Auth Sample in there to Signing an email/pass user:
I receive an error:
` // Create a user with the email and password.
public Task CreateUserWithEmailAsync(UserLoginDetails userLogin)
{
Debug.Log(String.Format("Attempting to create user {0}...", email));
// DisableUI();
Problem is that you cannot execute Unity related outside Unity main thread.
What is the correct method to execute Unity tasks after signing ?
The text was updated successfully, but these errors were encountered: