I created a VFX with a changeable property “Mesh” making particles spawn from a common cylinder mesh shape. Works ok
Then I added a c# script to test changing the Mesh input in the VFX by setting a customizable “TST” (mesh) variable and trigger the change with a button click. I tested by selecting a common sphere mesh and on button click the VFX updates fine. So far so good
Then I added code so it would use a mesh from code instead of an existing asset. So I tried defining a mesh with a simple cube vertices.
As soon as i test this with a button click, Unity crashes. Without exceptions.
Anyone any idea why? Below is the code i used for the Mesh;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
public class changemesh : MonoBehaviour
{
public Mesh TST;
public VisualEffect VFXGraph;
void Start(){
}
void Update(){
}
public void buttonclick1(){
change1();
}
public void buttonclick2(){
init();
change2();
}
Mesh manualmesh;
void init(){
manualmesh = new Mesh();
Vector3[] Vcube = {
new Vector3 (0, 0, 0),
new Vector3 (1, 0, 0),
new Vector3 (1, 1, 0),
new Vector3 (0, 1, 0),
new Vector3 (0, 1, 1),
new Vector3 (1, 1, 1),
new Vector3 (1, 0, 1),
new Vector3 (0, 0, 1),
};
manualmesh.vertices = Vcube;
}
void change1(){
VFXGraph.SetMesh("Mesh", TST);
}
void change2(){
VFXGraph.SetMesh("Mesh", manualmesh);
}
}
