# Getting area of an object

Hello guys!

I’m quite new into Unity and I’m having some problems at making my project.

The things is, is there any way to get the area of an object?

What I mean is that I want to get something like the contour of an object, so I can know the surface that it is using so I don’t create more objects in the same place and they don’t intersect with each other.

I leave a pair of images here so u can understand better what I mean. In the first one I have an example object, and in the second one the thing that I would like to get in my surface to work with it (it’s just the same object but seen from above).

It’s of course going to take some math.

First off, you need to decide to what detail you want to define the bounds of the object. For example the MeshRenderer will return the ‘bounds’ rect of its mesh in the scene, but this encases the entire extents of the entire mesh, as opposed to a detailed region. Where as the mesh itself is a very detailed representation of it in space.

Furthermore, the object might not be a mesh at all, but instead a primitive object like a cube, or sphere.

Others might be composites of several things.

So you need to decide not just the detail of it, but also the complexity of it.

In the end though, all of them will be either verts or sphere/capsules (which are just verts with girth to them). You then project those down onto the surface (usually defined by the normal of the surface). The combination of all these projections is the total region of the object on the surface.

Thing is… now what? What are you doing with this information? If you need to test overlap of it with another shape… well then there’s some math there. If the detail of your projection allows for concave shapes, that gets even more complicated (2d intersection testing of convex shapes is rather trivial compared to concave shapes, due to the Separation of Axis Theorem, which is very efficient).

But really, what is the intent of all this? Are you just making sure two objects don’t intersect?

I had to do this recently, and all I did was define a collider on each of our entities that defines its region set to a specific layer. Then as it drags around I just overlap that with all other colliders to test if it is intersecting other colliders on that layer or not. If it is, it can’t be placed there.

Thank you for your response lordofduct! I’ll try to do it in that way

About the intent of this: I want to make cities with a “random” form, so I need to get the building surfaces so I can stick them to each other without intersecting them or getting too much distance between them. With this, I think I can get a quite realistic city using some kind of algorithm to place these surfaces.