Is scripting a level editor with saving and loading levels..

Is scripting a level editor with saving and loading levels possible?

I have an idea to make some prefabs ready and then i make a level editor ready so that the users can make their own Levels with the prefaps.

After that they can send this levels to friend so that they can play it.

What comes in my mind with that is the question if it is possible to restrikt the positioning of the prefaps in a special raster i.e. a 10cm raster so it is simpler for the users that the end of the prefaps match each other.

For that i think it is importent to build the prefaps so that it match exactly into the raster.

Mathias

Everything is possible, some things are harder than others though. :wink: Anyway, take a look at this, maybe it will give you some ideas.

–Eric

There are two basic methods. The one Eric’s linked to is a grid-based approach. This works great for a lot of games (especially RTSs), but it’s copmlicated to code and test and I think it’s limiting.

The other approach is “object-based”. Basically what this involves would be: in your level editor your user clicks on the “house” button, then clicks the terrain, and the house appears where they clicked. For the purposes of saving the level, you would add a reference to this object to an array; when you go to write out the level, you just loop through this array and write out a string that looks like: “House; pos=4.0,1.0,4.0; rot=0.0,0.0,0.0,0.0”. If you format the string like that, you can use any one of zillions of javascript snippets that read cookies to read the data back in, and use that to instantiate the objects when you load the level.

Yep, if you just want to place some arbitrary objects, then something like that is the way to go. Having also written such an object-based editor, I can say it’s definitely easier as long as you don’t care about things like objects overlapping and just let the user take care of that. You can still restrict the positioning of the objects to a grid by rounding the x/y/z coordinates to some precision (you mentioned 10cm, so that would be rounding to .1 using Unity’s scale of 1 unit = 1 meter). Also you’d probably limit rotations to 90 degree angles if you want to make sure stuff always lines up.

–Eric

Not sure if this is what the first guy was asking, or if your answers are implicitly giving me the answer, but …

Is it possible to use Instantiate() to permanently add an object to the Scene hierarchy? When I use it it creates a (Clone) which appears to only exist in the runtime data, not the scene data on disk.

But I’m doing something where it would be convenient, while playing, to hit a button and have some data automatically added to the scene. And the code for that’s easy to write, but of course the objects I create are gone as soon as the game exits.

Is this a superficial limitation with an easy workaround, or no?