Loading external/user-generated content

Hi, i’m evaluating engines for updates to two existing games i use in my classes and have been told that, while Unity is a great engine, it might not be suitable for my games. i’m not sure if there’s a New Customer Questions forum so hopefully posting in Support is the proper thing to do

The first game is a turn based strategy where players write their own AI. Currently, they write scripts (using a standard text editor), drop them into a folder and the game automatically loads them at run-time (the user then picks the AI to use in-game from a list). i’ve heard, but want to confirm, that a compiled game binary written in Unity cannot load script files from disk

The second game relies significantly on user-generated content. That content includes a set of images and a descriptor file. At run-time, the game scans the user-generated content directory, reads the descriptor file for various things (images and various AI-related stats) and loads the items into the game. i’ve been told that a game binary compiled with Unity Pro might be able to load images but that the Indie version cannot (as a teacher, i obviously prefer the cheaper version :slight_smile: ). i want to verify both of these statements

The current game engine i’m using handles both of the above quite easily (other things, unfortunately, like unloading textures so that i don’t run out of texture memory, which i do constantly, it doesn’t so well). However, i haven’t figured out how to get it to handle two other features i’m interested in.

First, to make user-generated content easier, i wanted to include a simple in-game paint program and can’t figure out how to do that with my current engine (i see no way to generate new images).

Second, students have requested the ability to save screen shots of their work, which in this case is character they create. My current engine can save the current screen as an image but not a section (the character portrait) of the screen, nor can it save the images with alpha (they want to save the character portrait but not the background). i don’t know if i can do either of these things with Unity

Unity can do all that:

You can execute arbitrary code loaded at runtime in Javascript using the eval() function, although it’s likely you don’t want to do that, but would be better off writing a simple scripting language of your own, which would be able to load text files and run them in a more controlled environment.

There aren’t any image types that Unity Pro can load that Unity can’t; you can use .jpg and .png in both. (Technically you can use anything, but for everything except those two, you’d have to write your own image format parser.)

You can write a simple in-game paint program fairly easily (I think there might already be one on the wiki), and saving an arbitrary section of the screen is no problem.

–Eric

The issue, i was told, was loading something at runtime. Something about not being in a resource bundle or somesuch (sorry, i don’t know the Unity terminology). In my case, we give people the game and they can add their own clothes, portraits or what have you by dropping them in the Clothing directory

So what i heard is that, while building the game, i can add any images i want, but when i give the game (binary, not source) to someone, they can’t add new images because it wouldn’t be packed in the Unity resource bundle

In the current game, i scan a directory looking for text files and the contents of those files are something such as “type=shirt, pose1=someImage.png, AIProperty=something”. i assume Unity can scan a directory for files and then parse them, i’m just wondering if it can add new (user-generated) images to the game after it’s been built

But it’s great to hear i can do the rest. i prefer they write their AI in C#, so hopefully there’s an equivalent to eval() for that, but if not, Javascript is probably fine for most tasks. And i haven’t got a clue how you create a new image in Unity and then save it to disk but if you say it can do it, all that means is that i need to download Unity and start reading documentation

you can load anything but you have to load it yourself.
Unity won’t offer you any support to do so for anything else than movie, texture or sound.

So you can load images into textures and load scripts into javascript for execution… can you load a file format that you created yourself, provided you write the parser, ie load individual bytes from the file? And can you write such files to the user’s harddrive using Unity?

You can load any arbitrary file using the WWW class with a file:// URL and get its data as text or a byte array. The Buffer class (see here: Buffer Class (System) | Microsoft Learn) might be useful for coding binary data and the various System.IO classes (see here: System.IO Namespace | Microsoft Learn) can be used to set the directory and write the file, etc.

That’s good to know, thanks. So basically then if I want to save objects/meshes/animations etc off I need to devise a file format of some kind and write the importer/exporter.

Is it possible to look in a folder and load all the images without first knowing their file names?

(how would I look in a directory and find all the files and their file names?)

only if it is a standalone player.
Then System.IO offers the required functionality with the directory reader etc