Collider mesh

Hi, what’s the best way to have an invisible collider mesh? I need it for raycasting (without rapier) but it should not participate in rendering.

I’m sorry, I couldn’t find a response but notified the team :robot:

Hi, the easiest way would be to disable the Renderer component in e.g. Unity.

If you prefer to not have a Renderer component (maybe you add the mesh via code to the scene) then you can use setCustomVisibility(yourMesh, false) to exclude the object from being rendered (Note: this won’t affect child-objects. If your mesh has children they would still be rendered unless you also set the customVisibility flag).

That’s what I tried :slight_smile: Disabling the renderer results in the mesh not being used in the raycast at all.

Ah of course, sorry. Custom visibility sets a special flag on the layers which excludes it from rendering and affects raycasting layer checks too.

Have you tried simply setting the layer of your raycast object to something else than the default and then disabling that layer in the camera layermask?

Example

Disable in the camera layers

To hide the object in the Unity Scene View too here’s a basic script (this is totally optional!)

#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;

[ExecuteInEditMode]
public class SceneViewCulling : MonoBehaviour
{
    public LayerMask layerMask = ~0;
#if UNITY_EDITOR
    private void OnEnable()
    {
        SceneView.beforeSceneGui += OnBeforeSceneGUI;
    }
    
    private void OnDisable()
    {
        SceneView.beforeSceneGui -= OnBeforeSceneGUI;
    }

    private void OnBeforeSceneGUI(SceneView sceneView)
    {
        sceneView.camera.cullingMask = layerMask;
    }
#endif
}

Ha, no. But that’s working like a charm. Thanks :slight_smile:

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.