- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 100
 
Open
Description
Hello everyone, when trying to update the materials on the brush, it gives an error, tell me where to dig, please
void CreateCSGCube(Vector3 position, float height)
{        GameObject cube = new GameObject("CSG Cube");
    cube.transform.position = position;
    var csgBrush = cube.AddComponent<CSGBrush>();
    csgBrush.transform.localScale = new Vector3(cubeBaseSize, height, cubeBaseSize);
    csgBrush.transform.SetParent(csgParent.transform);
    ApplyMaterials(csgBrush);
}
void ApplyMaterials(CSGBrush csgBrush)
{
    if (csgBrush == null)
    {
        Debug.LogError("CSGBrush for zero");
        return;
    }
    var surfaces = csgBrush.Shape.TexGens;
    Debug.Log(surfaces);
    if (surfaces != null)
    {
        Debug.Log("RenderMaterial select ");
        for (int i = 0; i < surfaces.Length; i++)
        {
            surfaces[i].RenderMaterial = colorDirtMaterial; 
        }
        surfaces[4].RenderMaterial = colorGrassMaterial; 
        csgBrush.Shape.TexGens = surfaces;
        Debug.Log(surfaces);
    }
    else
    {
        Debug.LogWarning("RenderMaterial not select CSGBrush.");
    }
    
    
}My Error
NullReferenceException: Object reference not set to an instance of an object
IslandGenerator.ApplyMaterials (RealtimeCSG.Components.CSGBrush csgBrush) (at Assets/IslandGenerator.cs:75)
IslandGenerator.CreateCSGCube (UnityEngine.Vector3 position, System.Single height) (at Assets/IslandGenerator.cs:65)
IslandGenerator.GenerateMeshFromTexture () (at Assets/IslandGenerator.cs:51)
PixelMapToMeshEditor.OnInspectorGUI () (at Assets/Editor/PixelMapToMeshEditor.cs:14)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <a97926197b3e45ed8df65b2d4f0f9d77>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)```
Metadata
Metadata
Assignees
Labels
No labels