Some advanced questions

I’m currently in the process of prototyping a City Builder game. I have 15 years of programming experience and am comfortable with both C# and C++. The questions I have are more on functionality of Unity rather than specific scripting errors. While my programming background helps me understand how to model the simulation I have zero experience with Unity and rendering engines in general. Also, I plan on using Unity Pro for the final product.

I have done extensive reading on these issues and can’t find one solid direction or answer, so I look to the community.

My first question revolves around assets. I understand when making an FPS game that the levels and content is static, however that is not the genre I am making. Much of my game will have to be moddable and extendable with addons by my company or fans. These can will mostly be building assets, and depending how extensable the system is I want to support the creation of as much content as I can. So can I make a standard ZIP file and have my own ZIP archive classes infuse the game with the content contained therein? If the next time I run the game and there is another ZIP file, can I integrate that into the game?

Everything I’ve read so far involves assets and asset bundles, however the customers who play the game shouldn’t be required to have Unity to create these assets. I want to include a “Building Editor” with the game that loads the building model and textures and lets them set up the metadata specific to the game and save it as a ZIP. The game would then have to be able to load it at runtime. Is this possible?

The second concern is threading. Naturally my game will have many simulations going on in the background. I’ll not get into their details at the moment, one example is I need something like a pathfinder to run in its own thread to prevent the FPS from dropping. And most important of all is the method the threads are able to talk to one another. Once a path is found for Citizen Y I need to tell the primary game object a path was found and the nodes and links associated with that path. Furthermore, if the player places a new road I need to be able to update the pathfinder with the new nodes and links availble to it. The traffic simulator will need to take the path usage data and set congestion/timecost values to the pathfinder. This process won’t happen every frame but once every game month, probably every 5 to 10 real minutes.

Since rendering is where I lack the most experience I’ve done extensive reading on the matter. I do have a couple questions that are important.

When rendering something like a building what exactly is the pipeline for that process? I’m aware that polycount is important, but what triggers a drawcall? Would UV mapping the building be beneficial or detrimental? I plan on having at least 3 LOD levels for each building. The LOD0 up close view being the most detailed. I want to be able to support normal, specular, and bump maps at this level. The more distant LOD1 would only support one of these maps. These would be buildings several hundred units away from the camera. (I’m planning on 1 unit = 1 meter at the moment.) LOD2 would be very far away and require very little detail.

At LOD2 the camera would be very high up. The crux of that is there would be hundreds of buildings on the screen. Even with these low LOD levels am I then limited by drawcalls? Would it be better to lock the camera at these altitudes to a certain angle and simply render the buildings as billboards? Wouldn’t that require just as many drawcalls? Can meshes be combined and split dynamically? Lets say a neighborhood has 100 houses and the player zooms way out, those houses are now LOD2, but there is still 100 of them.

One other huge area of concern are shadows. I need to include a day/night cycle. But I know dynamic lighting and shadows are a huge burden on rendering. How could I approach a solution that looks good and performs well? At LOD2 levels and the distance of the objects the shadows wouldn’t need to be very detailed, it’s just the sheer number of objects that is my concern. Am I correct in my understanding of shadowing that the scene is basically rendered from the lights position and shadows are calculated from what is hidden?

The inclusion of night time demands city lights. And I want to include in the “Building Editor” a way to add lights to the buildings. The user will need to be able to select a window polygon and set a flag for night time, thus making the polygon use (at night) a self illuminated texture to simulate a light is on. Other lights would mostly be directional lights. These lights would be used at LOD0 detail, LOD2 lighting would need to be baked into seperate self-illuminated textures while in the Building Editor. Thus when viewing a city from a distance would give the illusion that lights are on but not actually need to calculate the lights in real time.

A lot of this game will require pulling the fun of making a world within Unity into a game in and of itself. Aside from the game exe and Building editor exe I will also need to make a Region Editor. I’m already talking to a few people who’ve done some amazing things streamlining the process of making terrains, what I’m wanting to do is take the process of setting up terrains, splat maps, foliage, and water and make it its own application. The tools would be streamlined enough where all the user would need to do is select a tree family and use a brush to place them on the terrain. Terraforming, splating, etc would be handled the same way. Rivers would be created using a similar node-link system as roads as I’ve seen in many downloadable add-ons to Unity, only they would need to be done in my Region Editor.

I understand this is a huge project and have already gotten financial support from some very dedicated fans of the genre. Once I complete the prototyping I plan on getting funding and help from other developers and artists. Unity has an amazing community, but I’ve seen enough FPS/MMO/platforming games to last 10 lifetimes. I want to show that Unity is powerful outside of these genre’s and will put every effort into proving it.

Thank you,
Nick

Loading mesh at runtime is fairly straight forward you just open the file in binary or text and pull out the vertex information to feed into a mesh, unity has functionality to load textures a similar way.

There are a couple of threading “frameworks” on the asset store which will get you setup with threading in unity… it’s fairly straight forward… just don’t cross the wires! :slight_smile:

Draw calls are triggered by separate meshes, they can be batched if they share a material but it’s possible to “max out” this batching process by having too many objects or vertices (and if they are far apart in terms of distance).

You’ll find LOD code on the asset store to switch out your models so you don’t need multiple cameras, I believe unity has this built in also but I haven’t used it. However I did have my own switching out code awhile ago and all you need to do is ensure your mesh and textures are preloaded before you switch them.

You can gain a performance boost from baking all static shadows such as buildings and trees etc and then use dynamic shadows for your moving objects.

Everything you’ve mentioned is very doable, I’ve done some terrain editing stuff which could quite easily be packaged up into an executable. I used siaqodb, an object database to store all my data. The data is a single database which has many files but I could easily ZIP them up as a “save file”.

Regarding files and assets:

Threading is somewhat complicated by the fact that you generally can’t use the Unity API in threads, only thread-safe Mono functions. There’s still quite a bit you can do with threads, but from what you describe you at least some of that could be done with coroutines and/or InvokeRepeating anyway.

As for shadows, the docs cover pretty much everything here and here.

–Eric

Regarding shadows:
Baking shadows does what? If the “Sun” moves in the sky won’t a baked shadow be useless? Or would the baked shadow just scale with the movement of the Sun?

What are the upper limits on number of draw calls? I read 1000 somewhere but I would need to push this higher. Then again, I could also restrict the camera from going TOO high while in City Mode.

Buildings can’t share materials (does material = texture?). But if a particular model of building is built somewhere, can’t I instance it to build it elsewhere? Or does this not gain me any advantages? Say for example a house develops in that neighborhood of 100 houses, if that houses model is already being used can I just reference the mesh and save performance? So in said neighborhood of 100 houses there might only be 10 unique mesh’s being used. (You’ve seen the repetition of the suburbs.) Would I save on performance if I instanced similar models?

If I did, would it then be possible to vary coloring on those houses somehow? Say House 1 is blue, but can the same model house 2 built a little ways away be green and instance the mesh used by House 1? Does this method save performance any?

I don’t think you want baked shadows for something like this. Draw calls are limited by CPU power; there’s no real hard limit. Buildings can share materials if you use a texture atlas. There’s not really any such thing as “instancing” meshes…dynamic batching can help somewhat if the buildings are low-poly enough (and share a material), but ideally you would use the Mesh class to create combined meshes on the fly. So a single mesh could have 100 houses or whatever. You could use vertex colors to add color variation.

–Eric

Once the meshes are combined and the player zooms back in can the meshes be split back to their original individuality and LOD’d appropriately?

Of course.

–Eric

If the buildings had one UV mapped texture would this trigger a single drawcall? I don’t see re-using a lot of building textures as the game will support mods I don’t see a lot of texture re-use. Also, I don’t want re-use of textures to make the buildings look the same. Though, if performance demands it I think it might be wise to create a group of textures that are varried enough that it would work.

And what is a texture atlas?

Only if they are low-poly enough to work with dynamic batching, or (preferably) if you create a combined mesh yourself.

–Eric