Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

NullReferenceException running ProBuilder API from a build

Discussion in 'World Building' started by wahlerdigital, Mar 4, 2020.

  1. wahlerdigital

    wahlerdigital

    Joined:
    Jul 1, 2019
    Posts:
    16
    I can use the ProBuilder 4.2.3 API from the editor just fine but any build I create on macOS using Unity 2018.4 throws null refs when I try to extrude a face. Here is the script that will recreate the issue. Attach it to the default ProBuilder cube. Note that I also tried using the current preview source from GitHub, same problem.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.ProBuilder;
    5. using UnityEngine.ProBuilder.MeshOperations;
    6.  
    7. public class ExtrudeCubeAtStart : MonoBehaviour {
    8.  
    9.     public ProBuilderMesh ProBuilderMesh {
    10.         get {
    11.             if (proBuilderMesh == null) {
    12.                 proBuilderMesh = gameObject.GetComponent<ProBuilderMesh>();
    13.                 if (proBuilderMesh == null) {
    14.                     Debug.LogError("ProBuilderMeshOperations.ProBuilderMesh.getter FAILED to get ProBuilderMesh");
    15.                 }
    16.             }
    17.             return proBuilderMesh;
    18.         }
    19.     }
    20.  
    21.     private ProBuilderMesh proBuilderMesh = null;
    22.  
    23.     public void Start() {
    24.         Debug.Log("ExtrudeCubeAtStart.Start()");
    25.  
    26.         int indexFace = 2;
    27.         Face[] faces = new Face[1];
    28.         faces[0] = ProBuilderMesh.faces[indexFace];
    29.         ProBuilderMesh.Extrude(faces, ExtrudeMethod.FaceNormal, distance : 0.5f);
    30.         ProBuilderMesh.ToMesh();
    31.         ProBuilderMesh.Refresh();
    32.     }
    33. }
    Here is the stack trace:


    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 /Users/robert/workspace/unity/examples/Unity.2018.4/Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/Core/SharedVertex.cs:144
    at UnityEngine.ProBuilder.ProBuilderMesh.get_sharedTextureLookup () [0x00022] in /Users/robert/workspace/unity/examples/Unity.2018.4/Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/Core/ProBuilderMesh.cs:341
    at UnityEngine.ProBuilder.MeshOperations.ExtrudeElements.ExtrudeAsGroups (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IEnumerable`1[T] faces, System.Boolean compensateAngleVertexDistance, System.Single distance) [0x0003d] in /Users/robert/workspace/unity/examples/Unity.2018.4/Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/MeshOperations/ExtrudeElements.cs:372
    at UnityEngine.ProBuilder.MeshOperations.ExtrudeElements.Extrude (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IEnumerable`1[T] faces, UnityEngine.ProBuilder.ExtrudeMethod method, System.Single distance) [0x00013] in /Users/robert/workspace/unity/examples/Unity.2018.4/Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/MeshOperations/ExtrudeElements.cs:30
    at ExtrudeCubeAtStart.Start () [0x00029] in /Users/robert/workspace/unity/examples/Unity.2018.4/Assets/ExtrudeCubeAtStart.cs:29
     
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    548
    Your code works for me, testing on 4.3.0-preview.4.
     
  3. wahlerdigital

    wahlerdigital

    Joined:
    Jul 1, 2019
    Posts:
    16
    Did you test the code by doing a build and running stand-alone? Preview.4 does not work for me on Unity.2018.4 LTS. If you run it in development mode you can see the errors in-game.

    Also, even though I pulled down preview.4 via the package manager, I have to manually edit the cached packages to fix the missing HDR pipeline requirement fatal error.
     
  4. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    548
    wahlerdigital likes this.