Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Brush materials #401

Open
Kolhun opened this issue Jan 13, 2025 · 0 comments
Open

Updating Brush materials #401

Kolhun opened this issue Jan 13, 2025 · 0 comments

Comments

@Kolhun
Copy link

Kolhun commented Jan 13, 2025

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&)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant