How can I prevent my game from lagging?

Hello,

I am currently in the process of creating a huge level with lots and lots of objects. I don’t want my game to lag since it is such a big level…so here is my question:

Is it possible to have Unity render only the objects within a radius of a light (a spotlight, in this case)?

My goal is to place a spotlight above the player that will dynamically grow based on their movement. So, in theory, the only objects I want Unity to render are those within the radius of the spotlight. Everything outside of the radius of light would still exist, but would not need to be rendered until the player entered that portion of the map.

Any ideas? All information is greatly appreciated =)

–Velk

Have you looked at the culling volumes in the fps tutorial? That sounds like what you want. Another way is to reduce your camera’s far clip plane.

It’s easy to switch off rendering of objects. Everything else, including movement, collisions, etc. will continue as normal.

That said, Unity is pretty efficient at culling anything outside of the frustrum anyway. I’d just code it as simply as possible and optimize if necessary later (premature optimization is a bad idea).

Thanks for the information. I will definitely take a look at the culling options in the FPS tutorial.

Much appreciated =)

–Velk

I think it is very worthwhile to spend some time figuring out the minimum detail needed to give the graphic effect you need.

For instance, I have a road that looks great and uses a 16x16 texture. I couldn’t use a smaller texture and have the same look, but any larger than that doesn’t add any detail to the scene.

Terrain detail is another aspect that can be tweaked to a dramatic effect. How many different levels of height do you need in a terrain? How small do you need each bump to be? I reduced a 3MB heightmap to 26KB for one of my games. There was no noticeable difference in gameplay or graphics, well, that is except for an extra 20 FPS and a decimated load/download time.

The examples above are going to be extremely project specific. However, once you figure out what the base level of detail for your project is, you will save yourself a lot of time designing things. You will gain a LOT of FPS, and you will wind up with a much more consistent gameplay experience.

Not too soon, it isn’t.

Premature optimization pretty much never saves you anything. E.g. suppose your texture looks good at 8x8 and great at 16x16 and no better at 128x128 … ok it might take you 30 minutes to figure this out. Does it make any difference in the end? Turns out the 3MB height map is FAR more important…

But this is more than premature optimization – you’re advocating premature target specification. The beauty of Unity, and a lot of modern content tools, is that it can scale to hit different targets, but if you’re made all your models and textures low res because you assumed you’d target last year’s low end Mac, say, and suddenly you’re targeting next year’s game console – well, you’re screwed. It’s always easier to throw out resolution (in 2d and 3d) when you need to, than put it back in having left it out for bad reasons early on.

Moreover, you’re better off working on making the game actually work than tweaking content early on. Who cares if this texture is just right if the model it’s on ends up being replaced later?

Aim High and Be Flexible.

In Photoshop, this means building textures out of bezier objects where possible. You can rescale up or down as required.

In most 3d modeling tools, this means using varying levels of subdivision, and making a tradeoff as appropriate.

You’re much better off using these techniques than picking a target resolution and working within it as though it’s a fixed thing. You may want to INCREASE resolution. You may find yourself targeting two platforms, one where geometry is expensive and texture is cheap (e.g. a lot of desktop PCs), and another where geometry is cheap and texture is expansive (e.g. most consoles, especially Sony PS2).

I guess I was talking about making the decision about the scope of your game.

For example, if you are making the next WoW, then yes, your fifty-man development team should focus on scalable assets.

However, if this is a hobby project for you, I doubt you would ever need to spend more than a couple of hours updating your assets for a better/worse/ gaming system.

If you aren’t going to be making the most amazing looking game ever, it’s better to focus on finesse with your graphics rather than brute force detail.