Search Unity

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

Discussion in 'Scripting' started by LoneSurvivor82, Oct 16, 2020.

  1. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    42
    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:

    Code (CSharp):
    1. using UnityEditor.ProBuilder;
    2. ...
    3.  
    4. public void Awake()
    5.     {
    6.         pb = GetComponent<ProBuilderMesh>();
    7.     }
    and later on:

    Code (CSharp):
    1.  
    2. protected void FinishMesh()
    3.     {
    4.         pb.ToMesh();
    5.         pb.Refresh();
    6.         pb.Optimize();
    7.  
    8.         pb.RebuildColliders();
    9.         Collider collider = GetComponent<Collider>();
    10.         collider.enabled = false;
    11.         collider.enabled = true;
    12.     }
    13.  
    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
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    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. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    From the scripting reference:
    https://docs.unity3d.com/ScriptReference/UnityEditor.html
     
    LoneSurvivor82 likes this.