How to make raycasts work on a newly made collider

I want to do raycasts on a mesh, now it appears that raycasts only hit front facing triangles, but I want it to hit both back and front facing triangles.

Unfortunately this doesn’t seem to be optional, so instead I make a new mesh, copy all vertices and triangles, and add all triangles again in reversed order. And then assign this new mesh to the collider.

Now here’s the problem, when I do this, every and any raycast results false.

Unless, I first make the collider and keep it in the scene, then select it and change some values (and set these back to how they where before), and then do the raycasts, and then it suddenly does work.

So what’s wrong? (and how do I fix it?)
It’s as if something needs to happen to a new mesh before it can be used, something that happens automatically, but not immediately it seems.

have you tried RaycastAll?

I only want to do raycasts on the one mesh.

I use Collider.Raycast

but if there’s a way to do raycasts on a mesh without making a collider first, I would prefer that.
(I don’t get why they made it like that, I would prefer a function like: Mesh.Raycast(ray, hit, distance, bool IncludeBackfacing))

Found the answer here: How to assign procedural mesh to a collider - Questions & Answers - Unity Discussions
and here: Dynamic mesh collider - Questions & Answers - Unity Discussions

It appears it works if you first create the mesh and then assign it to the collider,
rather than assigning a new empty mesh, and then setting the vertices and triangles (which was what I actually did).
Otherwise it also works, but only after 1 frame or so.