Making random map, how to do this well?
Hello, I'm actually making a "Isaac-like". I made a script who load all the map in my prefabs and then instantiate them with a procedural generation. I think this part is ok. But my problem come from prefabs. In each Map I load, there are various amount of bushes (the bushes are childs prefab of the "Map"). I have actually 20 maps like that. I just changed the sprite of the bush, the original prefab changed, but not every ones in the maps prefabs. I would like to know how to link the bushes which are in the Map to the original prefab. And i would like to know if there are better way to do this. My maps is made of a grid so maybe it would be easier (or better) for the game to put the informations in a document the game will load? but i really don't know how to do this. If it's more convenient to do this, do you have some ressources about this?
If you don't understand me clearly, don't hesitate to ask me more details.
Thanks in advance
Answer by Oukalakakou · Mar 16, 2016 at 05:08 AM
Why not trying to serialize your maps. So your maps will not be prefabs anymore. You will just have to do one prefabs for each game object that can be in your map like the bush and so all your bushes will be connected because coming from the same prefab.
You will need a script to save and load maps though.
Serializing something is saving it in a file? (like a xml one?). I never did this, i really don't know how to do this. Do you have any tutorial?
Is it lighter than every maps in a prefab?
Thanks for your answer
Yes serializing is saving to a file. I don't know a good tutorial about map serialization but there is a good tutorial about persistent data for beginners in the unity tutorials here.
I don't know if it will be lighter but I think so because only relevant data will be saved,.
The spirit of doing that is to create some kind of converter that will create a file referencing your map or create a map after a file. It's not so difficult to achieve but it depends a lot about the kind of map you want to get.
Is it a grid map?
Oh nice thanks. I'll check that. Yes it's a grid map. I guess serializing is easier with a grid map?
And do you know how to solve my problem without serialzing? (linking the bushprefab included in the mapprefab to the original bush prefab) (that doesn't seem clear...)
Serializing with a grid map could be easier because you just will have to save an array of data representing your game objects to instantiate.
You could link your bushes but I don't think you could do that with prefabs. What you want is something like a prefab of prefab.
Do more than one map is istantiated a the time or do you create a new scene for each map? I'm a big fan of isaac and I think for doing a game like that just one map have to be created and when you enter another you should enter another scene. So why don't create scenes ins$$anonymous$$d of prefabs for your map? Like that prefabs will be linked to instantiated game objects.
Hum, I have a scene for each level (in isaac it's basement I, basement II, cave I ...). Do you think i have to make a scene for each map? (A map is the "square" which contains only few bushes and some ennemies). If I make a Scene for each map, won't it be heavy? And can i load many scenes in another scene?
(Thanks for helping me :D )
I don't think there is a good answer to your question. Sometimes you just have to make a choice and stick with it.
If I were to make this kind of game, I would have created a data structure representing my different rooms and how they connect to each other.
A scene is what is really loaded into your game so splitting your games in more scenes will certainly result in better performances. Why keep in memory rooms that are not visible?
I want to keep them in memory because it's more like an old zelda than isaac. The full map is load, and the player can walk free between the "rooms".
I found some things like "poor man nested prefab" but i have to look further for 2D scripts. I'm a beginer and i don't have the time to learn how to serialize.
Thanks for your help @Oukalakakou