How do I remove a material from a Craft entity?

Project that tries to apply and remove a material from a Craft Orc model:

-- setup function
function setup()
    --make scene
    craft.scene.main = craft.scene()
    local scene = craft.scene.main = color(235, 158, 72)   = color(66, 40, 30)   = color(130, 50, 50)   
    --make entity
    orcEntity = scene:entity()
    orcEntity.model = craft.model(asset.builtin.Blocky_Characters.Orc)
    --make camera
    camView =,vec3(0,9,0), 50, 0,1000)
    camView.rx = 20
    camView.ry = -180
    --controls for adding/removing material
    parameter.action("Add Material to Orc", function()
    parameter.action("Remove Material from Orc", function()

function addMaterialToOrc()
    if orcEntity then
        local newMaterial = craft.material(asset.builtin.Materials.Specular)
        newMaterial.diffuse = color(255, 0, 0) -- Example: Set to red color
        orcEntity.material = newMaterial

function removeMaterialFromOrc()
    if orcEntity then
        orcEntity.material = nil -- Reset to default material

function draw()    

function touched(touch)

…currently crashes upon pressing the “Remove Material” button.

How would I make it work correctly? I want to get the Orc texture back when I remove the material.

Is it possible to make a blank material that does nothing but replace another material, while applying no effects itself?

Would the getMaterial and setMaterial functions help?

Could you make your grids out of voxels?!

@piinthesky are you addressing both my recent posts in one message here? :slight_smile:

I think the relevant function would be entity.remove(craft.material)… which in my experience either does nothing or crashes.

As to my other post about voxels: as a matter of fact the raycast does work on voxels, when I look at the code it seems like it’s not actually detecting the grid entity directly at all.

Exactly, i guess the grids dont behave with voxel raycast as they are not voxel entities. This was why i suggested to construct the grids using voxels.

@piinthesky we should continue this in the post actually related to the grid, ok?