Bounds appear correct but are not working

I am trying to procedurally generate terrain using the jobs system. I seem to be having an issue with my bounds, but I don’t understand what is going on. I am visualizing my bounds and they are appearing as they should, but when I face them from the positive x direction and move close to them they disappear. I think it may have something to do with world vs local space, but I am not sure. I am setting the gameobject to appear in worldspace, and then setting the meshdata locally since I tried doing it globally before and messed things up, doing it locally seems to be what I need. I then set the bounds. When doing mesh.Recalcualatebounds it sets all of the bounds to the same spot, I have set the bounds and they appear correct, but as I said, there are issues.

The position of the gameobject is set as…

var overallPos = new int2((chunkPos.x * (mapWidth)),(chunkPos.y * (mapWidth)));
terrain.transform.position = new Vector3(overallPos.x,0,overallPos.y);

chunkPos is values such as (0,0),(1,0),(0,1) etc and then I use the mapWidth to set it properly in the world. I will leave out the code to keep it short, but I set the vertices, normals, etc locally, they all appear correct when I generate the meshes…

The bounds are set here…

var bounds = new Bounds(new Vector3((overallPos.x + ((mapWidth+1)/2 )),0,(overallPos.y + ((mapWidth + 1) / 2))), Vector3.one * (mapWidth+1));

This puts the bounds around each terrain chunk and it appears correct. See the following images

What do you do after calculating the bounds variable? You need to set it to your mesh, or your mesh renderer so Unity will know how to cull it. Keeping the bounds as a MonoBehaviour property will not work.
Something like this:

var bounds=.....;
meshRenderer.bounds = bounds; //just an example, see the doc for correct API

I was setting it as so…

var mesh = new Mesh()

mesh.bounds = bounds.

however, I have changed it to be…

terrain.GetComponent().bounds = bounds;

and it is now working. The bounds still display the same when I use Gizmos.DrawWireCube(boundsToShow[i].center, boundsToShow[i].size);

If you don’t mind, what is the difference between setting it to the meshrenderer bounds and the mesh bounds? I am also using a meshfilter along with the meshrenderer, which is what I set to the mesh.

In any case, thank you. I had tried using mesh.bounds instead of mesh.recalculatebounds before, which did nothing. I have a lot to learn.

You can use meshRenderer.bounds if your mesh has vertex animation in shader.
If you don’t set meshRenderer.bounds, Unity will use mesh.bounds for culling.