1
\$\begingroup\$

I'm working on a top-down rogue-like in Unity3D, and I already have some kind of dungeon generation.

The next feature I'd like to implement, is to predesign some kind of "event rooms" (i.e. boss fight rooms), so my algorithm could place them at random locations.

Is there some kind of Unity feature for this, or I have to implement an editor script which could save and load tilemaps into and from scriptable objects?

\$\endgroup\$
1
\$\begingroup\$

You can design each event room on a separate tilemap and then save that tilemap as a prefab. Those prefabs can then be referenced by ScriptableObject's or directly by the script which does your dungeon generation.

If your architecture allows for more than one tilemap, then you could simply instantiate the event rooms. This would have the advantage that the room prefab can actually contain more than just a tilemap. You can put literally anything you want in there.

But if your architecture assumes that there will only ever be one tilemap in the scene, then you need to copy the tiles from the prefab into the actual game tilemap. You should be able to do that with prefabTilemap.GetTilesBlock and mainTilemap.SetTilesBlock.

\$\endgroup\$
  • \$\begingroup\$ One thing I am actually not sure about is if the last paragraph will result in the tiles being cloned or the tiles being references to the original tiles in the prefab tilemap. That difference might be relevant if you have scripted tiles with internal state. \$\endgroup\$ – Philipp Sep 10 at 9:38
  • \$\begingroup\$ Thanks, this is what I wanted to do as well, but thought Unity has something for this. I will wait a bit more, maybe someone got a better way. \$\endgroup\$ – Tudvari Sep 10 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.