Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to build open world map?

Discussion in 'Game Design' started by supadupa64, Mar 10, 2016.

  1. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I am building an open world map. The problem is that there is too much lag. Can I just split up the map into scenes and place a trigger to load the next map scene while the player runs around??? Or is there a better option?
     
    Last edited: Apr 5, 2016
  2. Philip-Rowlands

    Philip-Rowlands

    Joined:
    May 13, 2013
    Posts:
    353
    This sounds more like an implementation question than a design question. Especially since that is probably the simplest way to do it.
     
    AndrewGrayGames and Kiwasi like this.
  3. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Wow this is the first comment I've had on my posts. I guess there are people here. Now that I know that map splitting is a thing I guess I'll do that! But since I haven't done this before, do you know of a tutorial on this?

    I figure if I want to split my map in 1/4 I'd just make a copy or the main map four times and just keep the 1/4 I want for each scene and delete the rest?
     
  4. Philip-Rowlands

    Philip-Rowlands

    Joined:
    May 13, 2013
    Posts:
    353
    I don't know of any tutorials, but the general flow I'd use when entering the trigger area is this:
    1. Calculate the direction in which the player is moving. If you can gaurantee that they will be facing the way they're going (i.e. not walking backwards or sideways), this will become a bit easier.
    2. Check which sector they will be entering and leaving. (e.g. leaving sector 1 and entering sector2).
    3. Disable sector 1 and enable sector 2. It's generally good practice to enable/disable objects rather than deleting them outright - garbage collection can have a massive performance hit.
     
    AndrewGrayGames and supadupa64 like this.
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    supadupa64 likes this.
  6. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    I haven't dabbled in asynchronous levels myself, but I believe this might come in handy.

    You would construct scenes so that they fit together perfectly, and only load/unload when it was safe that the player cannot possibly see or interact with the section being loaded/unloaded.
     
    AndrewGrayGames and supadupa64 like this.
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    This topic overlaps design and implementation, since your implementation choices may significantly affect your game and level design.

    The biggest source of framerate lag is probably overdraw. Use aggressive occlusion culling to tell Unity not to draw things that aren't actually visible. This may solve all your lag issues. It's mostly an implementation thing, but the way you design your level determines how effective occlusion culling will be.

    If that doesn't fix it by itself, considering using levels of detail on your GameObjects' logic (i.e., the scripts). If a GameObject is moderately far from the player, make its scripts do less processing -- for example, running perception checks less frequently, or switching from a complex animation system to very simple animation. And if the GameObject is really far from the player, consider deactivating it entirely.

    I offered the suggestions above because they're easier than setting up geometry streaming.

    If you're talking about lag when loading the level, or if it's constantly paging memory to disk or in and out of GPU, then yeah, you're going to have to stream parts of the world in and out. If you want to test the waters with a free but bare-bones solution, there's a link to Scene Streamer in my signature below. At the very least, feel free to scavenge the code for ideas on using LoadLevelAdditiveAsync. SECTR Stream and World Streamer are much more sophisticated, though, being paid products. They provide tools to help you actually split up your world into separate scenes.

    On the design side, a lot of games use "airlock" sections where you can stream sections in and out while the player is in a small section with lots of turns or doors that ensure that the he or she can't see other sections popping into and out of view -- think of Mass Effect's elevators for an obvious example.

    Vast, open landscapes are harder to design for streaming. But mountains, thick forests, and things like that can make good section borders that works like airlocks.

    An important implementation detail to keep in mind is that, when you additively load a level, all the new GameObjects will run their Start methods at the same time. This can cause a very pronounced stutter. Try to avoid doing any work in the first frame of Start. Instead, spread the initialization work out over several frames. The Start method can be a coroutine, so this is pretty easy to do.
     
  8. BingoBob

    BingoBob

    Joined:
    Feb 26, 2016
    Posts:
    80
    Not experienced programmer but this is my view as a consumer.
    just because your system can render that entire world scene doesn't mean my PC can. I would expect to have the ability as a player to adjust the draw distance/view distance.
    I would try to make any performance issues adjustable by the player.
    It may still be reasonable to keep the separate world scenes to as a way to provide feed back to the player that he is progressing.
     
    Dracones and supadupa64 like this.
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    In pure implementation terms I've built a world based on dozens of chunks. Every few seconds I checked what chunk the character was in. I queued any of the eight chunks around the character that were not yet loaded. Then I would quietly load each chunk in the background. Character speed was limited so that they could not actually reach a chunk that was not yet loaded.
     
  10. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    @BoredMormon right (He's one of the forums most helpful members, btw). That's how most of those games work from what I understand, but you may want to increase the area from 9 tiles to 16 to avoid pop ups. Just make sure that the on and off measurements have a gap so you don't have the game try to load and unload several times in a row.

    If it were me, I'd make an empty object then a low res terrain with no collider. Lay them out in order on the right places. Then add them to a list. Have the list check the one or more of the objects distance to the camera per frame and keep moving through the list again and again. If the terrain is within a certain distance to the camera asynchronously load a high res terrain with a collider (and all the items and enemies) and disable the low res one. If it gets too far away, disable the high res and enable the low res. If it gets even further, destroy the high res terrain. You could then have a slider to determine the load distance to tweak it for performance.

    Oh, and there's a LOT of goodies you could get for the terrain.
    RTP is good.
    So is Advanced Foliage Shader.

    Lastly, there's a few "hic-ups" that may catch you off guard. You'll need a terrain stitching script (there's TONS on the asset store), a way to import splat maps, and how to deal with resetting the world coordinates if the map is too big (otherwise, things bug out when you get too far from 0,0,0).

    Also, there's LOTS of things that could be bogging your game down.

    What's your profiler look like?

    Is it bottle necking on the GPU for sure and not the CPU?

    Make sure to cache objects that move every frame. Make sure that you add rigid bodies to all moving colliders. And make sure that you are using an object pool when possible over initiate and destroy. Those are all issues I've had in the past with performance.
     
    Ryiah likes this.
  11. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    BTW, this is such an ongoing question.

    Why are there not more videos on how to make open world games?
     
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Flattery for me all round today! Thanks

    Hmm, that might be an interesting topic. I have to do something useful with the infinite terrain system I have here.
     
    Rombie, Not_Sure and Teila like this.
  13. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Heh, maybe you could do the terrain and could do a tutorial on an RPG engine to use with it.
     
  14. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    This is some very good information! I've looked all around and I can only assume there isn't more information because people don't usually tackle this type of project? Anyway, I'll attach my profiler results. My latest one is just slammed with rendering. I don't know how to make complete sense of the results so maybe you guys can put in your two cents about it. I'm asking about the map splitting now since I figure it may determine how I create the rest of what I've start out to do. It would be so much easier to just finish building out the entire thing and then split it up, but I've got stuff all over. I started building up instead of out and it seems to make the lag worse... o_O Like BingoBob was say earlier, my desktop computer may be able to render the entire world at once, but I know probably most computer wouldn't be able to do that. I loaded it up on my laptop and it about exploded.
    As I've tracked my results, it just keep getting worse since I keep adding lots of objects to the scene. I can't add any water worth looking at (lags like a boss), so I ended up just deleting it all (very sad). profiler_results.jpg
     
  15. Deleted User

    Deleted User

    Guest

    Geez, heavy.. But this is something you gotta learn to do and is becoming too specific to be a design question.. But I'll go into some concepts, firstly.. Share materials to lower draw calls, make sure batching is having the desired effect, make sure you've run Umbra (occlusion culling), on the terrain you can do things like play around with the base bitmap distortion and density of the mesh heightmap.

    Seems shadowcasters are a big issue there as well, Umbra should help but make sure you're level design is smart enough to occlude as much as possible, try disabling shadows and / or cut down the shadow distance / quality to see how much impact that has.

    Other things, what hardware are you running? Like GPU / CPU? Also why are you running fraps (or equivalent) that will actually slow things down.
     
  16. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Motherboard: GIGABYTE GA-990FXA-UD3 AM3+
    Solid State Drive: Crucial m550 SSD
    Processor: AMD FX8350 - 8 core
    Memory: 24gb DDR3
    Graphics Card: EVGA GeForce GTX 960
    Power supply: 900 watts
    Liquid Cooled
     
    Not_Sure likes this.
  17. Deleted User

    Deleted User

    Guest

    Yeah, well the performance shouldn't be anywhere near as bad.. 6.8 Million tris is a sign you have quite a bit in your scene, but as I have scenes with double that and have it running on lesser hardware it shouldn't be an issue.

    Look into what I said, you'll need to get deep into optimisation ;)..
     
  18. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I was looking into this https://www.assetstore.unity3d.com/en/#!/content/5017 as a solution. This actually could help quite a bit I think as it reduces drawcalls, but it looks like this type of asset is for finished product (as in you're not going to move it, ever). I guess it may be a solution for things I know I'm not going to move.
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Have you turned off all postprocessing effects to narrow down whether the slowdown is in postprocessing or frontline rendering?

    How aggressively are you using occlusion culling? Good occlusion culling will give you more bang for the buck than just optimizing meshes and materials -- it's faster to draw nothing (i.e., culled) than to draw something slightly faster (baked mesh or texture atlas). Also keep in mind that if you bake too much together, or at least not judiciously, it will adversely affect occlusion culling.
     
    Not_Sure and Kiwasi like this.
  20. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I started setting up culling, but honestly I don't really see how this affects performance. I was looking at the examples on the Unity docs and the first thing they suggested was "your level geometry must be broken into sensibly sized pieces." So.... yeah, that's unlikely to be happening here. lol? I have my clipping plane set to 200 which is likely the minimum distance before I start having problems with being able to see great stuff in the distance. TBH though, I don't know anything about postprocessing or frontline rendering. baked.jpg
     
    Last edited: Mar 15, 2016
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    By postprocessing, I mean fullscreen image effects, such as Bloom and Depth of Field, that are applied after the main rendering cycle. Some of these can be really heavy. It's a quick test to inspect your main camera, turn them all off, and see if it affects performance.

    If your clipping plane is 200, then without culling Unity will render every single object within your camera's viewing frustum, even if it's blocked by 100+ other objects and there's no chance the camera can see it. This is called overdraw, and it's wasted work every frame that you want to minimize. The occlusion culling page does a decent job of showing the difference:

    Without culling:


    With culling:


    So you can see that without culling it's doing something like 6-8x the work.

    These best practices were written for Unity 4, but they still apply.

    I cut my teeth on Unity's occlusion culling interface with this 3DBuzz tutorial but it looks like there are other, newer ones, too.
     
    theANMATOR2b and Not_Sure like this.
  22. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Ok, so I baked my scene, but I don't see the slightest bit difference in performance. Does it automatically apply once baked? I looked around and saw that quite a few objects behind things were still showing... Although, do colliders block the view because I know I don't have colliders on everything since there's no way some of that stuff could be seen behind these rocks at my start where the camera is right now. baked1.jpg
     
    Last edited: Mar 15, 2016
  23. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Ok, so I've been testing the culling. I know there are still some things in the scene that will improve the culling and I know it's not actually working correctly since it shows things through my rocks (I don't know how to fix this yet...). I tried setting them to static but that didn't work. After the first round if culling I had a small performance increase. I assume if I can get it to work correctly it will help a ton. Here's the stats to compare to before the cull. culling.jpg
     
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Outdoor scenes are harder to set up for occlusion culling. It's a lot easier when you have solid interior walls, floors, and ceilings that very obviously occlude farther rooms. Maybe you could add some mountains or cliffs that could act like walls.
     
  25. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Now that you mention it. It would be a great idea to add terrain inside my rocks since they don't block anything. I'll give that a try.
     
  26. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Ok, so I added terrain inside my rocks combined with culling to decrease the render view and there is a significant difference. Verts down a COUPLE MILLION, lol, thousands of less draw calls and up a solid 8fps. Decent start here. I guess once I can't see any way to add terrain inside objects I'll have to resort to something like this: https://www.assetstore.unity3d.com/en/#!/content/5017

    Does anybody know of anything that will act as a wall for occlusion culling? Colliders? I haven't figured out what actually works yet except terrain. An invisible collider would be the most amazing thing if that was a thing. rendering2.jpg
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    It sounds like you've already started following the steps in the Occlusion Culling documentation. Some things to check: make sure you've marked as much as possible Occluder Static and Occludee Static, set up your occlusion areas, and play with the bake settings such as Smallest Occluder. The occlusion areas link has a good section at the bottom on testing and tweaking your occlusion culling setup. This blog post also has good tips for choosing bake settings.
     
  28. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I'll check those things out.

    I just built my game and made a playable test game. After these modifications I'm running a solid 40-60fps in game play. It may dip to high 30's for far views of intense detail, but for the most part it's completely playable. Of course I did put the settings on "fastest," so that made a big difference, but I really can't tell that much of a graphics drop. On "fantastic" settings it's more like 25-35 fps during game play. So there's still a lot of optimizing that needs to be done.
     
    Last edited: Mar 19, 2016
    TonyLi likes this.
  29. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
     
    Last edited: Mar 18, 2016
    DBarlok, mgear and TonyLi like this.
  30. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
  31. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Is there a way to mass select objects in scene in a certain area?

    I have thousands of objects and i want to select all the objects in an area. How can I do this without selecting each one without using hierarchy?
     
  32. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Like this? Click and hold the left mouse button in the Scene view and drag it over the objects you want to select.
     
  33. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    yes, that. Is this possible?

    Like this below, but nothing gets selected...

    selection.jpg
     
    Last edited: Apr 1, 2016
  34. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Strange. It's drawing the selection lasso, so I'm surprised it's not selecting anything. Press 'W' to enter Translate mode, and then try again. Are you perhaps using a third party editing plugin that's preventing this operation? That's all I got. Anyone else?
     
    Martin_H and supadupa64 like this.
  35. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I just tried it again and it worked! Wow, this would have saved me TONS of time if I knew about this before. I was baffled that Unity didn't have this type of mass select feature. Guess it works now. Thanks!
     
    Martin_H likes this.
  36. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I made a collider with a trigger to play an audio sound one time when I walk through it. The problem is that I get stuck in it for a second or two or more when I go through it. See Video

    It appears to be only a problem when I add the audio clip to the collider. I have another trigger collider with a notification that works great.

    How can I fix this?

     
    Last edited: Apr 1, 2016
  37. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Are there any error messages in the Console view?

    Is Third Person Controller perhaps interpreting the trigger collider wrong somehow? Would it help to change its Layer?
     
  38. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    [SOLVED] I changed the layer to Ignore Raycast and it worked. THANKS!!!!!!!!!!!!!!!
     
  39. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    supadupa64 likes this.
  40. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    By the way, I did decide to split my world map into sections and load scenes as the player moves through the world.

    I discovered that I just had too many objects (about 25,000 atm) in my one huge world scene and disabling them created the difference of lag and no lag.

    I will still likely be mesh baking some objects together to help increase the rest of what could be drawing too many calls.

    gamedesign.jpg

    http://www.indiedb.com/games/ruction-the-golden-tablet
     
  41. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    I did discover that if I disabled an object I can't select things in the scene though.. It's like it gets disabled.
     
  42. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Ok, so I split my map into sections because I was using a script to load scenes when I moved into a collider. So in each new scene I literrally moved my character into the place where he should load when the scene loaded, and then when you move through another collider to move back into the previous scene I could place my character there again, but about what when I load another scene from another location. I don't know if that even make sense. but I need a better way to load my character to a certain spot when loading a new scene. What is a good way to do this?
     
  43. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Are you loading the section scenes additively into your main scene, or completely switching to the new section scene?

    Here's a very hacky workaround: Since you're using the Dialogue System, you could use the MoveTo() sequencer command. Create an empty GameObject in the place where the player should be. Add a Sequence Trigger set to OnStart. In the Sequence, use MoveTo() to move the player to the empty GameObject's position.

    It's a bit hacky, but it might work. There are probably better solutions. Scene Streamer is free but simple and not very feature rich. World Streamer and SECTR Stream are much more robust.
     
  44. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    The way I figured out was to just go through a collider trigger and load the next scene. The Scene Streamer looks awesome and got me thinking, but I think that would just make things more complicated for how I have my map set up. I might work, but I really need to have all scenes disabled at once besides the one I'm in. I guess unless I made some random small scenes in between each actual scene as a buffer type scene...

    The way I currently have it set up: Each scene is a copy of my main scene with "scene" parts enabled only. I have a player in each scene. I figured since everything carries over I just position the player where the new scene begins and it works... Until I enter back into my main scene from multiple areas and I can't have my character appear in multiple places. Anyway, it's not going to work.

    So, about this dialogue system workaround... Here's what I have:

    I'm guessing I need my trigger to load next scene and my moveto object in another scene. I need my scene trigger to talk to my object in the other scene. I'm missing the connection.

    scenechange.jpg
     
  45. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Since you have multiple entry and exit points, you'll need to adjust the Sequence Trigger idea or take a different approach. This is really far from the core purpose of the Dialogue System, but hey it works and requires no scripting. :)

    Here's how to set up Sequence Triggers with multiple entry points:

    1. In your dialogue database, define a variable named "EntryPoint".

    2. On each exit point collider trigger, add a Sequence Trigger and a Lua Trigger, both set to OnTriggerEnter.
    • On the Sequence Trigger, set the Sequence to LoadLevel(destinationLevel)
    • On the Lua Trigger, use the Lua wizard ("..." button) to set the "EntryPoint" variable to a unique value of your choosing (e.g., "airlock").
    3. In your new scene, add empty GameObjects at each entry point. Add a Sequence Trigger to each one, and set it to OnStart.
    • Set the Speaker to the empty GameObject itself.
    • Set the Sequence to MoveTo(speaker, X-marine)
    • Expand Condition. Add a Lua Condition, and use the Lua wizard set it to Variable["EntryPoint"]=="airlock" or whatever unique value is appropriate from step #2 above.
     
    supadupa64 likes this.
  46. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Tony, you my friend, are a genius. It totally worked! It did take like 13 seconds to load in the editor, but I did try it with a built and it only takes 3 second. Acceptable. So far I only tried it from scene1 to scene3, so when I make more scenes I'll have to keep trying it.

    Thank goodness for Dialogue Systems, lol. Thank you!
     
  47. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Whew, glad it worked! ;)
     
    supadupa64 likes this.
  48. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    It's still working. I tried it going only one way before. I tried it going back and it worked great. Seems to be great so far.
     
  49. supadupa64

    supadupa64

    Joined:
    Feb 20, 2016
    Posts:
    175
    Has anybody discovered a great way to do game testing? I'll explain better to what I'm looking for. I've been developing a lot of the game play and have been testing things. I have some work arounds I've been doing, but once long questlines have been setup it just doesn't seem reasonable to have to go through hours of game play just to get to where I want to test things and make sure it works correctly.

    In the end I suspect that is really the only true way to test it all, but maybe someone has done a lot of this before and figure out some great ways!
     
    DBarlok likes this.
  50. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Testing is complicated; otherwise games wouldn't ship with so many bugs.

    Automation helps a lot. You can look into Unity Test Tools, but that's a big subject unto itself.

    Since you're using the Dialogue System and you mention questlines, you can create Quest Triggers, Sequence Triggers, and/or Lua Triggers set to OnStart and put them on deactivated GameObjects. When you activate the GameObject, its triggers will run. You can set up these triggers to jump the questline forward to a specific point. It's a heck of a lot faster than manually playing through to that point. And it doesn't require any scripting.

    You can also use the Lua Console to manually change the Dialogue System's environment (for example, set the "numscrollsfound" variable to 9) on an ad-hoc basis, but it's usually better to set up triggers like above so it's easier to repeat.

    Let's say you have a "Collect 10 Scrolls" quest. You want to test the turn-in without having to actually run around collecting scrolls. Create a root-level GameObject called "TEST". Create a child GameObject called "Test Scroll Turn-in" and deactivate it. Add a Lua Trigger that sets the quest state to active and sets the numscrollsfound variable to 10. You could even add a Sequence Trigger that moves the player to the quest giver's feet. Set both Triggers to OnStart. Then play the game and activate the "Test Scroll Turn-in" GameObject to make the triggers fire.
     
    supadupa64 likes this.