0
\$\begingroup\$

I am planning a game played on a 2-D map, where some spots are "towns". When the player walks into a town, he enters a high-resolution map of this town; when he exits the town, he returns to the low-resolution map of the world (as in e.g. Ultima 4). My question is how to implement this enter/exit mechanism in Unity? I thought of two approaches:

  1. The world map and each of the town maps is a different scene. Entering/exiting a town is implemented by loading the appropriate scene using the scene manager.

  2. There is a single scene, but the maps are geographically separted. For example, the world map is in coordinates 1...256, town A map is in coordinates 301...364, town B map is in 401...464, etc. Entering/exiting a town is implemented by moving the player and the camera to the appropriate map.

Is there a better approach? What approach is commonly used to implement this mechanism?

\$\endgroup\$
  • \$\begingroup\$ You could also have all your maps in one place, and just disable the ones you don't want to see, and enable the one you do. All of these solutions will work. So implement one, and ask here if you run into a problem with your chosen solution. \$\endgroup\$ – DMGregory Apr 15 at 23:31
  • \$\begingroup\$ I think all approaches you suggested could work. I'd suggest to go for the one that feels the easier for your skills. \$\endgroup\$ – TomTsagk Apr 16 at 9:17
  • \$\begingroup\$ Agree that either of these could work. You can look at how games like Skyrim implement this - Skyrim essentially uses your approach #1, in that it just has individual cells for every dungeon, town and enterable area, and whenever the player hits the trigger point to enter/exit, it just unloads and reloads cells and places the player into the appropriate cell with everything rendered as needed. You can even do it yourself using scene console commands. \$\endgroup\$ – Sciborg Apr 16 at 18:27
1
\$\begingroup\$

There is never a best solution. Only the solution which is best for your game and your personal workflow.

However, I would suggest a third solution.

  1. One scene only
  2. Store every map as a prefab (The Grid object with the tilemaps and all the objects on the map)
  3. When the player switches maps, destroy the old map and instantiate the new one.

Why only one scene? I am generally not a fan of creating levels as scenes. The reason is that you usually have a lot of stuff you want to have in every level, like the UI, gameplay-controllers and the player game-object. Keeping all that stuff consistent between all levels can be a real pain. And then you also have the problem of passing data between scenes which can be another source of headache. Sometimes you won't get around it. If you want to use baked GI, for example (which you usually won't use in a 2d game). But when I can, I try to keep all levels in the same scene.

Why maps as prefabs instead of one large map? Performance could be a concern, but with today's hardware and Unity's optimized tilemap rendering you really have to try hard to create a 2d tilemap which is so large that you get performance problems (Believe me, I tried). No, the reason for this is mostly convenience. When you can edit every map in isolation, then you don't have to worry about keeping gaps large enough that the player doesn't get to peek. And you don't need to move stuff around (probably breaking a few triggers) when it turns out your estimations were off. And then there is the problem that active game-objects on other maps still do their stuff when the player is on a different map, which might lead to side-effects you don't expect. It also makes it easier to collaborate between multiple map designers, because they can work on different maps in parallel without interfering with each other.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Interesting idea, I will try that \$\endgroup\$ – Erel Segal-Halevi May 19 at 8:02
0
\$\begingroup\$

The first solution is a widely accepted standard, but the second solution works best for immersion and continuity. However, it may not be viable from a performance standpoint, depending on how large your map will be and how much computing power you are using elsewhere.

It is also important to consider the player's means of travel. It is never a good idea to require the player to travel very long distances at a slow pace. If I'm understanding your ideas correctly, the first solution would effectively reduce the map size and thus reduce the distance between any two given points on the world map.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Regarding your second paragraph: in all of these solutions the size of each environment's map stays consistent. Ie. You'd use exactly the same world map in all cases. The difference is whether the interior map exists in a different scene, or just outside the borders of the world map in the same scene (or in the same place as the world map but temporarily hidden until needed) \$\endgroup\$ – DMGregory Apr 17 at 10:57

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.