What is the maximum byte length of Application.ExternalCall? (and oh yea, it doesn't escape strings correctly)

We've been experiencing problems transferring long chunks of data through the Application.ExternalCall method. it seems like there is a hard limit to the number of bytes that can be pushed to JavaScript. This is NOT a limitation on the JS side. We have successfully sent the same data to and from other embedded objects (ex: SWF to SWF). Our research has yielded a result of around 12560 bytes. I would like to know, if this is a known issue... and if so, what is the real limit?

and oh yea: The method doesn't properly escape the characters passed to it. It seems that it escapes quotes (" => \") as expected, but does not escape slashes and/or line breaks (\, , ,\r,\f) which causes an unterminated string error on the JS side. Not to mention any text that already contains escaped characters breaks (example: \" => \\" should be: \" => \\\"). There are 2 (that we can think of) workarounds for this:

  1. Escape them (the slashes and line breaks) ourselves (but NOT the quotes) before they get passed through the Application.ExternalCall or

  2. Use the WWW.EscapeUrl method to URL encode the value and decode them on the other side

Both of these methods seem to work, but the url encoding adds a considerable amount more characters to what we are sending. Thus, reducing the amount of data we can actually send at one time.

Has anyone else dealt with this?

I don't see any reason for there to be a limit, so this sounds like a bug to me. Can you file a bug report with an example script which shows the problem, and details on which platforms (browser, OS) you are experiencing the problem on?

We have the same problems with a game we're creating, which passes fairly large JSON files from Javascript to Unity. Once they reach ~ 16KB, Unity chokes on it. (Un)escaping indeed is buggy too.

I can’t test it now, but does it work if you use String.Format(“{0}”, aVarWithTheData) as argument for the externalcall?

I think there is a problem with object types cast. This maybe enforces it to send the data as a string.