- Home /
Random tilebased Dungeons - Best practice?
I'm working on a dungeon crawler game (like eye of the beholder) with tile based levels / movement, where i want to create random dungeons.
Currently i have created 2 prefabs (floor / wall tile) and i tried to create a 15 x 15 area out of these tiles via
GameObject.Instantiate( Resources.Load("prefabname"), ......)
to load the prefabs, which is really slow...
What's the best approach here? Create clones of existing tiles via Instantiate instead of loading them via Resources.Load ?
I doubt this would be fast enough to create bigger levels, especially on mobile devices...
I've also seen someone (youtube tutorial) creating meshes via script and texturing them, which seems to be really fast. Is this the best way to do this?
I don't want to use an existing dungeon generator or something, much more fun figuring out everything myself. Just need a little push in the right direction :)
How do other people create tile based levels (via script)?
Use Resources.Load once to get a reference. Instantiate from the reference.
If you are producing a lot of levels consider using an object pool ins$$anonymous$$d of instantiate.
Answer by FullHeartGames · Jul 29, 2015 at 11:45 AM
I am too working on a Random tile-based dungeon game and just released a demo on the Asset store if you're interested!
If you are interested in purchasing this I could also supply some tile based movement script! Good luck!
Answer by wpdev · Jul 29, 2015 at 08:51 AM
I did it the following way: 1. cut all map on squares, each square is a prefab, which store all containing gameobjects data 2. each visible square dynamically loaded using Resources.Load 3. when prefab is loaded, it immediately getting from pool all its gameobject and setting its data.
So basically saying square prefab contains only gameobjects data like position inside square\scale\rotation but not gameobject itself. That's why each square is very lightweight and could be loaded very fast during runtime. When square become invisible it gets unloaded and all containing gameobjects return to pool. Consider splitting loading\unloading each square for different frames, for example you need to load 5 new squares and unload 5, then next 5 frames unloading one squre per frame and after loading new squares the same way.
The answer is more than half a year old.
Anyway, I'm surprised nobody here mentioned yet that using seperate GameObjects for each tile (let along for each floor, wall and ceiling) is very bad practice. What you do ins$$anonymous$$d is Generate the mesh for all tiles as one by code, or split it into chunks if the vertex count gets too high. Even a smallish 25x25 dungeon will produce 625 GameObjects, and this will proably already lead to performance problems.
Your answer
Follow this Question
Related Questions
Lightmapping and Diablo3-style big-tile levels 0 Answers
Tile game instatiation 1 Answer
How to seamlessly tile terrains 0 Answers
Procedurally Connected Mesh/3d Model Tiles? 1 Answer
My precedural Algorithm for Tidy TileMapper is not working! 3 Answers