Can't build when I'm using functions from UnityEditor.ProBuilder in the code

Hello everyone,

I am using some methods from the UnityEditor.ProBuilder-Assembly in my code, namely

Optimize and RebuildColliders because I am doing some mesh-manipulation on runtime:

using UnityEditor.ProBuilder;
...

public void Awake()
    {
        pb = GetComponent<ProBuilderMesh>();
    }

and later on:

protected void FinishMesh()
    {
        pb.ToMesh();
        pb.Refresh();
        pb.Optimize();

        pb.RebuildColliders();
        Collider collider = GetComponent<Collider>();
        collider.enabled = false;
        collider.enabled = true;
    }

This works when I am in editor-mode, so the game compiles and I can start it.

But if I try to build the game, it fails with the following error:

error CS0234: The type or namespace name ‘ProBuilder’ does not exist in the namespace ‘UnityEditor’ (are you missing an assembly reference?)

Is there any hint you can give to build it successfully?

Thank you very much
Ricky

As a general rule, anything in the UnityEditor namespace is editor-only and not available in builds.

However, looking at the source for RebuildColliders in EditorMeshUtility, there doesn’t seem to be anything that requires it to be editor-only. You could try copying the code and adapting it to work in your own project.

3 Likes

From the scripting reference:

1 Like