Physics raycasts just ignore any mesh that is procedurally generated and is not saved as an asset.
In order to make them work, you have to interact with the collider component in the editor manually (enable/disable or just make any adjustment)
However, if you generate the mesh and save it as an asset, physics just works without problems.
Sounds like you just have a procedural generation bug.
When running, just pause the game, make a GameObject, add a MeshRenderer to it, then drag the reference that you made in the Collider into that MeshRenderer and see what your mesh actually looks like.
Or do that in your procgen code.
Unity is one of the easiest game engines to debug visual stuff like this using cheap-and-cheerful instant-visualizations like above.
Cant share code as it is a big and messed up project, but here is a video of the problem.
You are supposed to see the red brush circle on the mesh when i try to paint and see a debug log about the hit collider at the console, but it wont work unless i enable/disable the mesh collider component.
This only happens if the mesh is on memory, if i save the mesh as an “asset” before painting, it just works.
MeshCollider ← isn’t notified about the mesh being changed and by extension there isn’t a new “baked” physics mesh being created to reflect those changes.
I can see this being both a blessing and a curse, depending on usecase.
One way around it is to store the MeshCollider of the mesh you are currently editing and simply null/reassign the sharedMesh property of the MeshCollider each time you edit (not great) as you are effectively rebaking the collision mesh each time you change things. Which makes sense from an SDK implementating pov.
Keep in mind that this is as heavy as us picking up the change and rebaking the collision mesh each time the graphics mesh changes.
I’ll chat with @Vera_mg about it and see if it makes sense to add some opt in/sync method for this case.
Thing is, as you see in the video there are 2 tools, one for creation of a mesh and assigning the components and sharedmeshes. And the second is a painting tool which uses a GetComponent() on the mesh collider.
I believe this is a bug on the native mesh objects pointer in memory.
This was not an issue until 2022.3.49f, it was working on 2022.3.46f, something changed inbetween.
Nothing changed in that area for MeshCollider in a very long time inside the 2022LTS code. So maybe something changed in Mesh, yet looking at the history of the mesh implementation that does not seem to be the case :-/.
I’ll take a look at those versions and get back to ya ^^.
What is your point? I dont understand. In your example; you edit vertices of a mesh without syncing to physics with the obvious outcome. Nothing suprising.
But, do you understand the actual problem i am pointing at?
Just to let you know, the problem disappeared after i cleaned the cache at C:\Users\Me\AppData\Roaming\UnityHub and projects library folder.
Dont know why, but im happy.