Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Updating Brush materials #401

Copy link
Copy link
@Kolhun

Description

@Kolhun
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.