Hello to all, can anyone help me with probuilder face subdividing via script. I can extrude face via script but not subdivide. Am I missing something? I’m using the latest unity and latest ProBuilder imported in the project.
Thank you in advance!
I think connect elements might do that trick:
https://docs.unity3d.com/Packages/com.unity.probuilder@4.0/api/UnityEngine.ProBuilder.MeshOperations.ConnectElements.html
Here’s a thread where similar topics have been discussed:
I can confirm ConnectElements does work:
// pb is your ProBuilderMesh object
ConnectElements.Connect(pb, pb.faces);
Thank you so much guys, it does work and i have creared cube from script but when i deploy to android i have this error
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.ProBuilder.BuiltinMaterials.Init () (at <643dd6e0a1b0436996d4f97add324e4f>:0)
UnityEngine.ProBuilder.BuiltinMaterials.get_defaultMaterial () (at <643dd6e0a1b0436996d4f97add324e4f>:0)
UnityEngine.ProBuilder.Face..ctor (System.Collections.Generic.IEnumerable`1[T] indices) (at <643dd6e0a1b0436996d4f97add324e4f>:0)
ProBuilderPlane.Construct (UnityEngine.Vector3[] points, System.Single extrudeAmount) (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
Assets.Map.Map.GenRegionTrigger (Assets.Map.Center SelectedCenter) (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
Assets.Map.Map.<GenerateRegionTriggers>b__44_0 (Assets.Map.Center center) (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) (at <319b5411003b47fbaceecace494b6f79>:0)
Assets.Map.Map.GenerateRegionTriggers () (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
Assets.Map.Map..ctor (System.Int32 numberOfPlayers, System.Collections.Generic.List`1[T] playerOccupationColors, UnityEngine.LineRenderer lineRenderer, UnityEngine.GameObject playerStartSphere, UnityEngine.Color32 colorMarkToFlood, System.Collections.Generic.List`1[T] ringsData, System.Byte interactableCellAlpha, System.Byte selectedPlayerSphereAlpha, UnityEngine.GameObject cellSelectionSphere, System.Int32 elevationOfSphereMultiplyer, System.Single triggerHeight, UnityEngine.GameObject actionPanel, UnityEngine.UI.Button actionButton, UnityEngine.GameObject cardsPanel, UnityEngine.Transform cardsLayoutPanel, UnityEngine.GameObject cardPrefab, UnityEngine.UI.Text statsGoldText, UnityEngine.UI.Text statsExperienceText) (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
WorldMapManager.Awake () (at <7926f12d1fbd482bb6cb0f799a0b945b>:0)
Can you help guys? All im doing is the same code from getting started and include this Connect and thats it. Im using latest Unity (lwrp template) and latest probuilder. Thank you all again!
Are you positively sure that it works everytime in editor? Can you post your code?
I am positive, here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
public class ProBuilderPlane : MonoBehaviour
{
public Material material;
public Vector3[] mypoints;
public int[] myindexes;
void Start()
{
Construct(mypoints, 1.0f);
}
public GameObject Construct(Vector3[] points, float extrudeAmount)
{
mypoints = points;
int[] indexes = new int[points.Length * 3];
for (int i = 0; i < points.Length - 1; i++)
{
indexes[i * 3] = 0;
indexes[i * 3 + 1] = points.Length - i - 1;
indexes[i * 3 + 2] = points.Length - i - 2 == 0 ? points.Length - 1 : points.Length - i - 2;
}
myindexes = indexes;
ProBuilderMesh quad = ProBuilderMesh.Create(
points,
new Face[] { new Face(indexes) }
);
quad.Connect(quad.faces);
quad.SetMaterial(quad.faces, material);
quad.Extrude(quad.faces, ExtrudeMethod.FaceNormal, extrudeAmount);
quad.ToMesh();
quad.Refresh(RefreshMask.All);
quad.gameObject.AddComponent<MeshCollider>();
//quad.gameObject.GetComponent<Renderer>().sharedMaterial = material;
return quad.gameObject;
}
void Update()
{
}
}
I don’t undestand the Construct(mypoints, 1.0f) line. When in Construct method, this literaly executes mypoints = mypoints. Where do mypoints and material vars get initialized?
You can set up points in the inspector, create 5 elements in mypoints, (0,0,0)(1,0,0)(1,0,1)(0,0,1)(0,0,0) and just crate one material with lightweight rendering pipeline mat. It is true that we generate our points with voronoi diagrams and feed them inside and construct a mesh. But even with this simple setup it trows error on android.
Setup img: Unity ProBuilder Setup - Album on Imgur
Do you mean that you define those points in the inspector at editor time, and then you build the project?
Yes, sorry for delay, my team and i have reported this bug and ot has been updated in probuilder package 4.3.0 preview 1. Check it out