I have a tool that will generate a Mesh Collider
in editor from an existing Mesh Filter
’s mesh.
I want to be able to raycast in editor to place objects onto that newly generated collider, but the raycast only hits the collider after play mode has been entered. I have verified that the collider is valid by dropping RigidBodies onto it at runtime.
Raycast results before entering play mode:

Raycast results after entering playmode:

It is worth noting the image in the picture is not a generated collider, but results in the same issue.
Is there an additional step that needs to be taken so that the raycasts will work without having to enter Play Mode?

Idk, works just fine on my machine 
using UnityEngine;
[ExecuteInEditMode]
public class LetsRaycastAtEditTimeShallWe : MonoBehaviour
{
[SerializeField] float _maxDistance = 100f;
[SerializeField] LayerMask _layerMask = ~0;
void Update ()
{
Ray ray = new Ray( transform.position , transform.forward );
if( Physics.Raycast(ray,out RaycastHit hit,_maxDistance,_layerMask) )
{
Debug.DrawLine( ray.origin , hit.point , Color.red );
Debug.DrawRay( hit.point , hit.normal , Color.cyan );
}
else
{
Debug.DrawLine( ray.origin , ray.origin + ray.direction*_maxDistance , Color.yellow );
}
}
}
@andrew-lukasik is that a generic mesh? I’m aware it works for built in types, but I’m generating my Mesh Collider in editor.
Works fine with procedurally generated mesh as well
I added Mesh Collider
component manually in this example

I haven’t seen your code but what might be happening is that either your Ray
/Raycast
code contain a mistake OR you are raycasting this mesh before Physics system received this mesh’ data.
@andrew-lukasik the raycast code works, but only after play mode has been entered; that’s the problem. I need the Rayast to be able to work before entering play mode. I know everything is set up correctly because once playmode is entered, colliders and queries work as expected.
The question is what extra step needs to be taken for that to happen? I’ve already tried using Physics.BakeMesh
and even simulating for several timesteps.