- Home /
How much data can I send from the browser through unityObject.SendMessage()?
I want to download content into the Unity web player from a web site that does not host the web player/game. Thus, I have to do the download using something like JSONP from the enclosing web page, rather than from within the plug-in.
So, I imagine that my game will call out to the JavaScript in the browser to start up a jQuery JSONP fetch request. Once that request completes, I need to call unityObject.SendMessage() to send the data back in.
Is there a limitation to how much data I can pass in as a string in this SendMessage() call? I'll likely want to put in hundreds of kilobytes in one go, representing things like a mesh, or a texture, that would be dynamically provisioned from some other site under my control.
I know how to secure the web player against maliciously injected content from rogue hosters, although it seems as if SendMessage() can be used to send arbitrary messages to arbitrary game objects, and thus every game object method would potentially need to worry about this kind of attack. I think it would be better if there was a narrower interface here... but that's beside the point in this question: How big a string can I cram into unityObject.SendMessage() and expect to get away with it?
You say you want to "download content", but the rest of your message describes what sounds more like RPC. If it is just content download you need, have you considered the WWW interface?
On a different note, you mention communication with "the enclosing web page", which is something I'm interested in but haven't looked into yet. Is it possible to communicate between, for example, the Unity game running in the webplayer and client-side javascript running in the browser page that hosts the web player? Tips appreciated.
As I explained in the first sentence, I cannot use the built-in WWW code, because the content comes from a web site other than the site that hosts the game. The built-in WWW class enforces the same-origin principle for all requests. ($$anonymous$$ind-of pointless I$$anonymous$$O because there are no HTTP cookies to protect from within Unity, but whatever)
I discuss the RPC calls available in the Unity API because that is the mechanism that Unity3D plug-ins use to talk to the enclosing web browser JavaScript engine. From the enclosing browser, I can use JSONP to make cross-domain calls to download the content.
Answer by jonas-echterhoff · Jan 20, 2011 at 09:26 AM
As far as I can tell from a quick look, our code does not impose any limitations (other then a 32-bit size field on strings) on SendMessage, thus theoretically allowing up to 4GB of data to be sent this way. In practice, this will very likely also depend on browser and JavaScript engine limitations, and I may well have overlooked something - so the only way you can be somewhat sure of this is to go and test it across various browser and OS configurations.
Your answer
Follow this Question
Related Questions
Label not updating when text changed through javascript send message. 1 Answer
Web Player SendMessage Array Parameters 1 Answer
Problem with UnityObject2.SendMessage | communicating with the web player 0 Answers
Send a message to multiple scripts within an Array - Javascript 1 Answer
SendMessage Not Working: JavaScript 1 Answer