- Home /
How to build walls like in eg the Sims?
I need to let the user to be able to build walls similar to the system in the Sims. I also want the user to be able to place doors and windows AND be able to modify his/her creations .
Just building walls isn't that big of a deal as I could just create a mesh for every wall built but what if the user wants to place a window in the wall? And what if the user wants to delete a segment of an existing wall? Do I somehow edit the mesh or should there be prefabs that are inatanced for every wall segment (say 1 meter length of wall) that can then be exchanged to a prefab with a window in it?
And if I go the route with having prefabs for "wall segments" then I end up with a lot of gameobjects in the scene, possibly generating a lot of overhead. I'm afraid that if I go ahead and implement a system that fills my requirements of being editable then I might end up sith something that has way too many gameobjects in a scene and is therefore unusable...
Answer by Cains · Nov 04, 2013 at 07:03 AM
You're right about generating a lot of overhead if every wall segment is an individual GameObject, I tried this route at first with my game and I didn't scale up very much before the FPS shot to unbearable slowness. My experience is in 2D where the only thing I'd have to change are textures and not the actual model which is much simpler, but I can give some ideas.
One option I can think of is to treat each wall segment as an individual GameObject, and when one is created it checks if there are walls next to it. If there are, it'll delete the two GameObjects and create a new single GameObject with a mesh modified to extend the original wall segment to be two wall segments.
The other option, which I think would be a little more complex, would be to treat an entire level as a bunch of giant cubes (chunks) like a Minecraft-style procedural generation made up of cubes. An individual wall segment would be one of these smaller cubes. Each of these small cubes could hold a number of vertices and triangles which you could manipulate to create the object in that smaller cube's position.
Thanks a lot for answering, you may have saved me a lot of time with your warning regarding overhead :) do you have an idea of the approximate number of objects you could have before experiencing a drop in fps?
also sorry I can't upvote you yet too low rep...
I can't say for sure, really because it depends on many things such as how much script is running per frame for each GameObject in its Update() function. I can tell you that if you get into hundreds of thousands of GameObjects, just their empty Update() functions will bog a high-end machine down to unplayable FPS. Thousands of GameObjects seem to work well for me, and I've never experimented with tens of thousands.
In your case to get an actual answer for your limits you'll have to do benchmarks. Just the fact that my game was 2D with flat quads and yours is 3D would probably create a big difference in performance.
And no problem, happy to help someone dodge a problem that forced me to re-code and re-think my whole game.
Ahh ok then at least I have sort of a ball park figure. It just might work with less than 10k objects especially if I modify according to your first suggestion by "attaching" new geometry to existing game objects. I'll see if someone else has any other suggestions as well otherwise I'll accept your answer in a few days.
I implemented a simple system for building walls in the editor for now. I figured then I can make sure a level doesn't have too many gameobjects myself. Works pretty nice and the terrain is destructible. The hard part will be to "merge" gameobjects but I'll get to that when it actually is a performance issue for me. So I'll accept your answer as it helped me out!
Your answer
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Unity Wall placement help 0 Answers
Determine whether or not model is "inside out" 2 Answers
snapping objects at runtime 2 Answers
Combining meshes (different materials) together for rotation/translation 1 Answer