x


File I/O access from Chrome Native Client

With the latest release of Native Client, it now supports disk I/O. This I/O is different than System.File.IO in that it's asynchronous, more analogous to WWW in Unity terminology. From https://developers.google.com/native-client/beta-docs/fileIO

With either of the techniques described above, you can imagine that file IO does not lend itself to a blocking model. As a result, functions like fread/fwrite don't work as intended. To handle file IO in Native Client you must adjust your file manager paradigm to an asynchronous model.

My question is: is there any way to access this functionality from a Unity project compiled for NaCl? Google does provide an example C++ read/write class at http://code.google.com/p/nativeclient-sdk/source/browse/trunk/src/examples/pong/pong.cc, but I have zero experience with C++. We can't just compile this code to a plugin, because as Unity says: "As with the standard webplayer plugin, native C/C++ plugins are not currently supported by NaCl."

more ▼

asked Feb 23 '12 at 09:47 PM

Julien.Lynge gravatar image

Julien.Lynge
7.3k 20 25 49

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I posted this to the forums as well, and a Unity Developer was kind enough to provide an answer:

There is currently no native way to do that in Unity with NaCl. I don't expect that we will directly expose NaCl FileIO APIs any time soon, as they don't map well to existing http://File.IO functionality (as you described), and exposing a specific NaCl File IO class seems to be too special cased. I think the preferred way for us to expose this would be to add the ability to load plugin DLLs in NaCl, but that is unlikely to happen in the short term either (I think that there are more interesting features to be added to NaCl at this point).

So, right now your only option would indeed be using HTML5 file storage using js. From what I can tell with my limited knowledge of HTML5 file storage, this should generally be possible, though you would probably have to encode the data as text to submit it to Unity.

You can read the whole thing here:

http://forum.unity3d.com/threads/124820-File-I-O-in-Native-Client

more ▼

answered Feb 24 '12 at 11:45 PM

Julien.Lynge gravatar image

Julien.Lynge
7.3k 20 25 49

(comments are locked)
10|3000 characters needed characters left

It would be helpful if Unity would post a technical page that explains exactly which NaCl features can be leveraged in Unity and some sample code of how to leverage them.

Being able to read/write from disk is a very powerful NaCl feature and would be extremely useful to Unity developers.

more ▼

answered Feb 25 '12 at 03:06 AM

jeffssmith1 gravatar image

jeffssmith1
46 1 2 3

@jeffssmith1

UnityAnswers etiquette is that opinions should be posted as comments rather than an answer. This helps with the flow of the Q&A.

I agree that a page of explanation of Unity in NaCl and what is/isn't implemented would be very useful. However, it sounds like NaCl support is still very much in development/flux, so I don't honestly expect anything for a while.

Mar 01 '12 at 12:28 AM Julien.Lynge

My humble apologies for the breach in etiquette.

Mar 09 '12 at 08:23 PM jeffssmith1
(comments are locked)
10|3000 characters needed characters left

This is not a question about if it's possible or not. It just doesn't allow you to access local files! All Unity players (standalone / webplayer / Android) are written in native code. In this case there's no problem for the player itself to access everything on the clients PC. The point is that unity created games / apps that are played in the Webplayer aren't allowed to access files.

The Unity3d Webplayer is a trusted piece of software which has to be installed on the clients PC. A game embedded in a website isn't trusted software.

There is no way for content that runs in the Unity webplayer to access local files. There is, will and should be no way to do something like that.

The best i could think of if some kind of drag and drop support, so the user fully controls what files can be read. Here's a feature request for this functionality

more ▼

answered Feb 23 '12 at 10:23 PM

Bunny83 gravatar image

Bunny83
45k 11 48 206

I'm not sure I agree with your assessment here. The other webplayer instances have no I/O access because they're sandboxed - it's just not possible to do. Here, NaCl has provided the functionality - it's not random I/O, it's an intentionally 'safe' way that Google has decided to block off disk space within the Native Client sandbox. I've never seen a statement from Unity that they simply won't allow disk access from webplayer if there are no technical limitations.

Furthermore, at this point we're no longer talking about a strict unity webplayer with the trust issues you imply - according to Unity:

"Unity 3.5 offers support to run Unity Web Player content (.unity3d files) using NaCl to allow content to be run without requiring a plugin install in Chrome."

Thus they're providing a wrapper into Native Client, not a browser plugin, and the app is distributed through the Chrome app store. This is somewhat analogous to the iOS/Android model, and Unity certainly doesn't restrict disk access there.

Feb 23 '12 at 10:35 PM Julien.Lynge
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x810
x56
x42
x1

asked: Feb 23 '12 at 09:47 PM

Seen: 1249 times

Last Updated: Mar 09 '12 at 08:23 PM