Search Unity

How to build the map system in "Metroidvania-like" game?

Discussion in 'World Building' started by Bagazi, May 13, 2020.

  1. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    611
    I am wandering whether the whole game map was build in one single scene in those "Metroidvania" game like Hollow knight ,which is made by Unity
     
  2. ron-bohn

    ron-bohn

    Joined:
    Oct 5, 2015
    Posts:
    318
    It's one common way for maps that I've seen. Make a simplified duplicate version the entire world/level and put it right on top of the actual level. Then you have a second camera render that in a viewport / ui and make it only render the map layer. You could also have icons for special items, enemies, waypoints, current objective etc that only render on the camera for the map layer.

    If you pick up an item that is on your map, just use whatever way you're removing/disabling/etc the game object in the level and do the same to your icon on the map layer. You can do a lot, if not everything you want this way.

    So you can basically have some AAA map features for linear levels without a bunch of possibly unnecessary code.

    It's good that the simplified map version which ideally shares 1 material atlas or utilize texture array to minimize cpu overhead. If you don't make a simplified version (gray for example), then your level will get rendered twice from your "map camera"...thus having double draws calls, for example. Definitely want to avoid doing that on a mini-map unless it's absolutely necessary for your map to be an exact bird's eye view of your level/world....which is really rare if not at all found in AAA....maybe racing games like rearview mirrors?

    If you have your map on a pause menu, then you could simply disable your player controller camera and enable the map camera, but this might not be needed in many cases since a slight lag on pause menu/map is not going to be anywhere near as noticeable as in a fast action bullet hell part of a game. If your pause map has some next-level particles, crazy animation, lots of skinned meshes and such then it could be a good idea to swap those cameras on and off.

    This also works for a mini-map hud during action gameplay.

    So that is one way you could do by the Hollow Knight example. I don't know if that's how they actually did it or not, but I wouldn't be surprised because I've seen it more than any other. Hope I didn't over-explain anything, just thought it might be helpful to others to know generally how to go about it. I don't know of a better way, although there could be one.
     
    rubendariohh likes this.
  3. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    611
    You mean there are two cameras existed simultaneously for mip-map and world-map separately? I am some confused about the drawcall part :confused: Anyway ,which I mostly concerned is about the load of scene, for instance,if the whole map was made in one single scene in hollow knight,would it will be to heavy to load? If not , is there some good rationally way to group those scenes ?


    PS: this is the mip-map of hollow knight... Looks like the game world is really big...
     

    Attached Files:

  4. ron-bohn

    ron-bohn

    Joined:
    Oct 5, 2015
    Posts:
    318
    Not sure what you mean by "mip-maps" ...not sure if that is a typo. Let's not get that mixed up :) I'm going to assume you meant the map screenshot in your attachment. Yes, 2 cameras would "exist" in your scene, it's best to turn off any camera when it's not being used. You would disable it, but it would still be in the scene hierarchy.

    For simplicity sake, let's assume we are just talking about 1 scene for now. If your game has multiple scenes it doesn't matter, you would just copy and paste the world map and camera to your other scenes (worst case scenario). So for multiple scenes, every scene would have 2 cameras.

    This depends on your rendering path to determine what would be best. Again for simplicity sake and to make an exact example, let's say we're using the following
    The screenshot "Hollow.jpg" you are looking a simplified version that I mentioned (the MAP camera).

    1) Combine the static objects and make them share one material. Do this and you'll have about 1-10 drawcalls depending on your shader, camera(s) and lighting set-ups.

    2) Batch the dynamic objects (like icons and item pick-ups that get disabled on the MAP and the GAME WORLD. Make sure they are all under 300 vertices (the lower the better) and make them share a second material. Depending on other factors, this will leave you with about 2-10 set-pass calls in the profiler

    So we have 2 materials total. 1 material for static game objects and 1 material for dynamic game objects. Assuming your skinned mesh renderers are optimized, you are going to have a very fast game level / world at this point.

    (In deferred rendering, you could leave your static game objects separate and take advantage of occlusion culling with your GAME WORLD camera. However, I would probably still combine the static objects in the MAP camera because static batching has some overhead and we're talking about how to make the game run as fast a possible).

    Lastly, for your GAME WORLD camera, there are the following basic ways to optimize.
    • Combine static game objects and make them share 1 material (also works for MAP camera), OR leave them uncombined and use occlusion culling which I've found to work best in deferred rendering because forward rendering gains a lot more from combining static game objects...again this all can depend on your target platform / device and is based on tests I've done.
    I hope this is more clear. I'm happy to dive into the exact details as far as I can for your rendering path and target platform. I say this because I certainly would not make the same recommendations for a low end mobile as I would for a high end PC and consoles can have their own unique specs for some of this stuff.

    But yeah using atlasing (or texture arrays), doing the optimizations above, using prefabs effectively, and keeping your overall VRAM under control it's pretty easy to make it not too much to load for your MAP camera to render the whole "simplified" version of the world.

    Basically, the GAME WORLD camera doesn't have to show the entire world, just the part that player sees. No reason to waste resources on rendering if your player doesn't see it. That just leaves you to manage the graphics memory appropriately and make efficient choices based on your art style.
     
    Last edited: May 17, 2020
  5. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    611

    Thanks for patient explanation, I guess I am more clear about this issue. I would use the Unity tileMap for world-building (with compoisted tiledmap for different layers),for the "static batching" tech as you mentioned,is there some typical example for reference? I dont know the exact way to do this,neither lack of ability to check the validity.

    I am not quite sure if Unity had help developer to do the "occlusion culling" stuff ,someone told me that Unity help doing it already. Anyway, in my case ,I would cease the animation or AI of the charaters or game objects which is out of camera. Is there any further optimization for culling?

    In my game, I would like to make it like "rougeLike" instead of static world map,that means maybe the map need to
    be generated dynamically before the scene loaded, I am wondering whether I should pick a bunch of game rooms ( could be considered as map unit )into one scene,when this game region was completed by player, another punch of rooms will be organized again for a new unity scene,just like the previous one. I noticed that in some game ,when a considerable size map be completed by the player, the game will be loaded obviously with progress bar prompt. I am wandering if it is the appropriate way to organize the whole world map..
    :)
     
  6. ron-bohn

    ron-bohn

    Joined:
    Oct 5, 2015
    Posts:
    318
    Most of what I said applies to 3D, but tilemaps are basically the 2D version of what I'm talking about. They use a sprite atlas. For static batching reference, I provided a link to the documentation above :) I'm not sure I can explain in any more detail than I already have. Static batching is something that every single unity developer should know about :)

    Did you get a chance to read through the culling documentation link I provided? There are several forms of culling. It's best if you just read up them directly. It took me a hundreds of hours to figure all this stuff out so expect to put forth some time in the documentation if you want to "check the validity". You can easily test it, and no offense but if you are not willing to test it yourself in 5 minutes, then would you help you further?

    Nobody can answer this for you without knowing your profiler information. That really is something that you need to figure out based on the information already provided. You might want to check out a "fog of war" system to accomplish what I think you're describing.
     
    Bagazi likes this.