Search Unity

ProBuilder in-game API changes

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

  1. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    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:
    963
  3. UpstreamAd

    UpstreamAd

    Joined:
    Jan 11, 2019
    Posts:
    10
    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:
    552
    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:
    28
    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:
    552
    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:
    100
    kaarrrllll likes this.
  8. superdupergc

    superdupergc

    Joined:
    Jun 21, 2013
    Posts:
    28
    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:
    28
    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
  10. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Wow this is super frustrating. Took me forever to find this gem of a thread and I did everything and I *still* can't get a custom action to show up.

    I've tried this with a brand new Unity project and directly cloning the examples repo and to no avail for the last 3 hours.

    And yes, I added the "ProBuilderMenuAction" as well... which is not documented anywhere and in fact looking at the existing actions in the ProBuilder package, they don't even use it. So what gives?!

    Broken links, lack of documentation, outdated examples.

    Please fix this and more importantly, tell me how to get a custom action to show up.

    Using the latest Unity 2019.1.3, ProBuilder 4.0.5.
     
  11. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    Documentation on that particular attribute is sparse, I agree. Just to make sure, this is the documentation page you were looking at, right? https://docs.unity3d.com/Packages/c...ProBuilder.ProBuilderMenuActionAttribute.html

    As for getting a menu action to show up, here is a quick example.

    Code (CSharp):
    1. using System.Linq;
    2. using UnityEditor;
    3. using UnityEditor.ProBuilder;
    4. using UnityEngine;
    5. using UnityEngine.ProBuilder;
    6. using UnityEngine.ProBuilder.MeshOperations;
    7.  
    8. [ProBuilderMenuAction]
    9. class MyProBuilderAction : MenuAction
    10. {
    11.     // In which section of the toolbar should this action be shown
    12.     public override ToolbarGroup @group
    13.     {
    14.         get { return ToolbarGroup.Object; }
    15.     }
    16.  
    17.     // If you do not provide an icon, your action will only be available in "Text" toolbar mode
    18.     public override Texture2D icon { get; }
    19.  
    20.     public override TooltipContent tooltip
    21.     {
    22.         get { return new TooltipContent("My Action", "Describe your action here"); }
    23.     }
    24.  
    25.     // Do whatever your action here
    26.     public override ActionResult DoAction()
    27.     {
    28.         var selectedMeshes = MeshSelection.top.ToArray();
    29.  
    30.         Undo.RecordObjects(selectedMeshes, "My Action");
    31.  
    32.         foreach (var mesh in selectedMeshes)
    33.             mesh.Extrude(mesh.faces, ExtrudeMethod.IndividualFaces, .5f);
    34.  
    35.         return new ActionResult(ActionResult.Status.Success, "Extruded all faces");
    36.     }
    37. }
    38.  
     
  12. Aetrix

    Aetrix

    Joined:
    Nov 23, 2013
    Posts:
    12
    Hello to all, can anyone help me with Subdivide via scripting? I have a problem that I can extrude but not subdivide in runtime, why? How can I achieve that effect?