Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

ProBuilder in-game API changes

Discussion in 'World Building' started by lejean, Jan 30, 2019.

  1. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    172
    I just updated from unity 2017 to 2018 and I cant get any of the scripts I used to work anymore.
    -It can't find pb_object or pb_face anymore and I don't know what alternative variable names to use.
    -I can't find the actual probuilder api in the VS dropdown
    -I don't know what namespace to use for probuilder

    Any fixes for this?
    Can I actually still use probuilder at runtime?
     
  2. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    493
  3. UpstreamAd

    UpstreamAd

    Joined:
    Jan 11, 2019
    Posts:
    3
    Hi there, @gabrielw_unity thanks for making such a great tool. I have also been using an earlier version of Probuilder to generate our rooms.

    https://twitter.com/ajlangridge/status/1032226442766102528

    In doing so, I use a lot of helpful things that pb_face and pb_edge can do, i.e. get faces by material, trawl through groups of faces for adjacent edges, remove faces from the mesh blah blah blah. I was wondering 2 things:

    Is there an up to date API reference that can help me navigate the new API?
    Does the new API allow me to manipulate the meshes as powerfully as before? Are there examples replicating some of the functionality of pb_faces, edges etc?

    I'm itching to make the upgrade to the latest version, but want to evaluate the work/viability of doing so.

    Many thanks!
     
  4. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    123
    4.0.0 actually exposes a lot more of the API, and in a much more consistent way. However, to make this happen there have been a lot of changes. The first thing you will notice is that ProBuilder is now using Assembly Definition files (https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html). To use ProBuilder in your own code you'll need to reference the Unity.ProBuilder assembly in your own definition files.

    If you had been using the api before, the workflow is generally the same. In most cases you can just rename the old types prefixed with 'pb_' to their new signatures and be on your way.

    The scripting reference is here https://docs.unity3d.com/Packages/com.unity.probuilder@4.0/api/index.html
    There is a repository of examples here https://github.com/Unity-Technologies/ProBuilder-API-Examples
     
    superdupergc likes this.
  5. superdupergc

    superdupergc

    Joined:
    Jun 21, 2013
    Posts:
    17
    Thank you Karl, this was helpful. However, I think I am still missing something, because while it can see UnityEngine.ProBuilder, it cannot see UnityEditor.ProBuilder, which means I cannot see the MenuAction class to override. Or should I not be looking at the CustomAction example?

     
  6. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    123
    If you need to access the Editor code, that is in a separate assembly definition. Runtime is `Unity.ProBuilder`, and Editor is in `Unity.ProBuilder.Editor`. So if you are adding menu items for example you would need both assembly definition files to be referenced.
     
    superdupergc likes this.
  7. PassivePicasso

    PassivePicasso

    Joined:
    Sep 17, 2012
    Posts:
    46
    kaarrrllll likes this.
  8. superdupergc

    superdupergc

    Joined:
    Jun 21, 2013
    Posts:
    17
    Okay, one more issue. Now that I've got the asmdefs set up correctly, my tool compiles. However, the shortcut does not show up in the Probuilder menu. Nor does the example CustomAction "Make faces double sided". Is there some place we have to register the new tools, like before? I can't seem to find any code like that.
     
  9. superdupergc

    superdupergc

    Joined:
    Jun 21, 2013
    Posts:
    17
    Update: The custom actions all need the [ProBuilderMenuAction] tag above the class name. In addition, the asmdef should be set up to JUST be for the editor, not for the compiled builds.

    update2: The asmdef file that you create should be in the folder with your probuilder extension scripts and nothing else. It compiles everything under the folder as part of the asmdef. I had it in the root of my project and it caused me no end of trouble.
     
    Last edited: Feb 11, 2019