Executing EndInvoke() in the web player throws this exception: “This method is not supported in the unity web player for security reasons”
What security reasons? Why would you allow BeginInvoke and not EndInvoke?
Anyway, which is the legal way to execute a method asynchronously in the web player? Thanks.
I guess the security reason is the possibility to crash the whole browser that way.
commonly I don’t see why it would be needed actually, its a functionality required at standalone players when forcefully shutting it down, which you can’t do in the webplayer.
For normal shutdown its either no topic (the methods will end in a few moments anyway) or it has a loop and a loop condition which you can control from outside too.
I would normally use the common way for asyncronous functionality which are Coroutines with StartCoroutine, Yield, StopCoroutine
They are handled by unity and will be stopped when the associated game object is cleaned for example.
EndInvoke is not for shutdown. This method gives you the return value of an async method started with BeginInvoke.
Coroutines dont do real async threading which is needed.
I’ve never worked with BeginInvoke so this might be not be fully accurate: As I understand you, you need complete distinct threads to handle completely unity independent data, not just functionality that runs asyncronous of the main code
In that case there would be System.Threading directly, which is what I use for distinct threads
should I have missunderstood you and you use Unity functionality asyncronous, you can just as well use Coroutines, as anything that access Unity must be within the same thread as the engine.
Using a System.Threading thread also throws a security exception in the webplayer.
Is there a way to do multithreading in the browser?, if not im kinda screwed.
What I’m trying to do: a simple chess game. The chess AI is in an external dll and has a method FindBestMove. This method can take a while so I need to run it async. I’ve tried with BeginInvoke/EndInvoke and with threads and both don’t seem to work in the browser (Although it works just fine in the desktop)
Is there a page in the site which describes all the restrictions in the web player? Does the iphone version also has restricted access to mono functionality?
iPhone is restricted to .NET 1.1
I’m unsure if you are able to use multithreading in browser plugins on all browsers at all (which would be a requirement as it must work consistently on all). Firefox does not run on more than core actually. So a dev will likely have to answer that.
But as an alternative: What prevents you from splitting your calculation set? Just using threads does not solve the problem as the threads just take longer on slower systems to process the same set and thus it calculates less in the same time.
This can be replicated without threads but an asyncronous “calculation coroutine”.
Thanks for taking the time to answer, it would be great if someone from unity could clarify on this multithreading on browser issue.
As I say, it’s a single method in an external managed dll. This method does take a while so it needs to run async so it wont lock the game during execution. I’ve tried a couple a ways of doing this, it always works fine in the desktop but fail on the browser.
To adapt this to the ‘coroutine way’ the library would need some major refactoring, but I dont have access to the source.I could decompile it since it’s managed but it may not be legal at all, and if it were, I’m not sure how much overhauling it would need (The library is a chess engine, and those things can be kinda complicated inside).