Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

ProBuilder 4.0.x API namespace not found on unity 2018.3

Discussion in 'World Building' started by sand_lantern, Jan 18, 2019.

  1. sand_lantern

    sand_lantern

    Joined:
    Sep 15, 2017
    Posts:
    51
    Howdy, I had a bit of code written before that found all the probuilder objects on the scene and performed some operations on them that I needed. This was using ProBuilder 3.0.9 from the Package Manager. Everything was copacetic.

    Today I thought I'd go through and do some package upgrades and saw there was a new version of ProBuilder. Updating it broke my script though. My code isn't anything crazy, I'd say.

    Code (CSharp):
    1. //some more namespace...
    2. using UnityEditor;
    3. using UnityEngine;
    4. public class GeneratePolygonsFromMeshForGameObjects : MonoBehaviour {
    5.     [MenuItem ("Tools/Generate/Polygons/ProBuilder Objects")]
    6.     static void HandleProBuilder() {
    7.         GameObject[] objects = FindObjectsOfType<ProBuilder.Core.pb_Object> ().ToList ().Select (pbobj => pbobj.gameObject).ToArray ();
    8.         ProcessObjects (objects);
    9.     }
    10.     //Etc...
    After updating versions, It seems that Visual Studio can't find the ProBuilder.Core.pb_Object package. I looked through some of your example packages and they seem to be inconsistant as to what the namespace should be.
    https://github.com/Unity-Technologies/ProBuilder-API-Examples/tree/master/Editor

    I see both
    Code (CSharp):
    1. using UnityEngine.ProBuilder;
    2. using ProBuilder.Core;
    Visual Studio doesn't know what to do with either of them.

    Any suggestions from the powers that be? I'm assuming I'm doing something bone headed, just not sure what!
     
  2. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    ProBuilder 4 changed a lot from 3.0.9. Not only are the namespaces different, but they are now using Assembly Definition files, so you'll need to link the references in your own asmdef files.
     
  3. sand_lantern

    sand_lantern

    Joined:
    Sep 15, 2017
    Posts:
    51
    Ah! that's probably the missing link for me, as Unity seems fine but VS is throwing fits. I'll bet that's the issue though.
     
  4. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    29
    So, i tried to use the examples in my project. specifically, the mesh editor one. it works without any problem in unity editor when i play the project. but when i build the project it wont work. I can hover my mouse on cube face and the face color change. but when i want to drag the face these errors come up: (I have changed MeshEditor.cs a bit, so I put the code for each line after ** in errors)


    NullReferenceException: Object reference not set to an instance of an object
    at UnityEngine.ProBuilder.SharedVertex.GetSharedVertexLookup (System.Collections.Generic.IList`1[T] sharedVertices, System.Collections.Generic.Dictionary`2[TKey,TValue] lookup) [0x00001] in F:\unityTest\PCS\Library\PackageCache\com.unity.probuilder@4.0.5\Runtime\Core\SharedVertex.cs:145
    at UnityEngine.ProBuilder.ProBuilderMesh.get_sharedVertexLookup () [0x00014] in F:\unityTest\PCS\Library\PackageCache\com.unity.probuilder@4.0.5\Runtime\Core\ProBuilderMesh.cs:288
    at UnityEngine.ProBuilder.ProBuilderMesh.GetCoincidentVertices (System.Collections.Generic.IEnumerable`1[T] vertices, System.Collections.Generic.List`1[T] coincident) [0x00039] in F:\unityTest\PCS\Library\PackageCache\com.unity.probuilder@4.0.5\Runtime\Core\ProBuilderMeshFunction.cs:647
    at UnityEngine.ProBuilder.ProBuilderMesh.GetCoincidentVertices (System.Collections.Generic.IEnumerable`1[T] vertices) [0x0001a] in F:\unityTest\PCS\Library\PackageCache\com.unity.probuilder@4.0.5\Runtime\Core\ProBuilderMeshFunction.cs:550
    at ProBuilder.Examples.MeshEditor+MeshState..ctor (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IList`1[T] selectedIndices) [0x00019] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:25
    at ProBuilder.Examples.MeshEditor.BeginDrag () [0x00092] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:124
    *****m_DragState.meshState = new MeshState(m_Selection.mesh, m_Selection.face.distinctIndexes);

    at ProBuilder.Examples.MeshEditor.HandleInput () [0x00033] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:91
    at ProBuilder.Examples.MeshEditor.Update () [0x00031] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:60
    (Filename: F:/unityTest/PCS/Library/PackageCache/com.unity.probuilder@4.0.5/Runtime/Core/SharedVertex.cs Line: 145)


    Uploading Crash Report
    NullReferenceException: Object reference not set to an instance of an object
    at ProBuilder.Examples.MeshEditor.UpdateDrag () [0x00014] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:137 *****var indices = m_DragState.meshState.indices;
    at ProBuilder.Examples.MeshEditor.HandleInput () [0x00070] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:99 *****UpdateDrag();
    at ProBuilder.Examples.MeshEditor.Update () [0x00031] in F:\unityTest\PCS\Assets\Scripts\Modeling\MeshEditor.cs:60 *****HandleInput();
    (Filename: F:/unityTest/PCS/Assets/Scripts/Modeling/MeshEditor.cs Line: 137) *****var indices = m_DragState.meshState.indices;



    Does anyone else experiencing same thing?
    gabrielw_unity can you help please?

    I am using Unity 2019.1.5 and ProBuilder 4.0.5.
     
  5. sand_lantern

    sand_lantern

    Joined:
    Sep 15, 2017
    Posts:
    51
    That's a null pointer error. Looks to me like something isn't hooked up right or initialized. Make sure all your game objects have associations where you need them. Otherwise, put in a debugger where you changed code and see if you can back track why your objects are null.
     
  6. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    29
    Thanks for answer. Ive been trying to see why there is a null reference, but i couldnt. and again, this just happen in build version. not in unity itself. have you generate mesh and work with it in build version with probuilder?
     
  7. sand_lantern

    sand_lantern

    Joined:
    Sep 15, 2017
    Posts:
    51
    Oh, if that's a build error, it could be something like you have a script that uses the UnityEditor namespace in your game logic. By design, the UnityEditor namespace doesn't get compiled into final builds, it's just available for editor scripts and such. Not saying that's your issue, but it's the first thing that comes to mind.

    I actually haven't gotten to making a build with anything that uses probuilder yet.
     
    asa989 likes this.
  8. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    29
    its not a build error. the build finish successfully. and when I hover my mouse on one of the mesh faces, the face color will change. but, when I want to drag the face the error happens. I will try to dig more. maybe there is a solution for it.


    EDIT: Ok, I found where the problem is. In MeshEditor.CS there is a class name MeshState which runs a function name GetCoincidentVertices(selectedIndices). this little guy returns null in Build version. I have no Idea how to fix it. but I hope unity does it soon.
     
    Last edited: Jul 16, 2019
  9. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    152
    Could you post your modified code? That function should be working at runtime.

    Edit - Also, make sure that you have "Script Stripping" disabled in the ProBuilder preferences.
     
  10. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    29
    Thank you for respond and sorry for late answer. didnt have internet :)

    You dont need my code really. if you download the Unity ProBuilder API Example, and build "Mesh Editor" Scene, you will see that it wont work. However, I attached two files where i made some changes to make it work. but i know i will have problems later since my solution is not the best!

    There are two other things to mention:

    1- I can't file mesh exporting API. like if i want export OBJ after building the project.
    2- in mesh editor scene, if you hold "Alt" + Left mouse button, you will have Gimbal lock at some point.

    Please let me know if you need other information from me and thank a lot for your help.
     

    Attached Files:

  11. asa989

    asa989

    Joined:
    Dec 18, 2015
    Posts:
    29
    Hi @kaarrrllll just wanted follow up on this topic? :)