Applying material within SimpleMeshMod

Is there a way to apply a material from within a SimpleMeshMod without triggering and recursive loop of the object changing?

When the Enable button is pressed, i want the material applied, otherwise I'm planning on then restoring the original material. But i can't even get the temp material applied without it crashing. Do i need to store the material in a local variable and not the param block?

clearlistener()
 
plugin simpleMeshMod myMaterialModifier
name:"MaterialModifier"
classid:#(0x491fdf76, 0x7493038e)
(
    local tempMaterial = MultiSubMaterial()
 
    parameters MainParams rollout:MainRollout
    (
        isModifierActive type:#boolean ui:uiIsModifierActive
        previewMaterial type:#material
    )
 
    rollout MainRollout "Main" rolledUp:false
    (
        checkbutton uiIsModifierActive "Enable" width:160 align:#center
    )
 
    /* Actions */
    on create do
    (
        previewMaterial = MultiSubMaterial()
    )
 
    on modifyMesh do
    (
        if isModifierActive then
        (
            /* Material */
            format "Preview Material > %\n" previewMaterial
            format "Node Material > %\n" owningNode.material
            format "== %\n" (owningNode.material == previewMaterial)
            if owningNode.material != previewMaterial do 
            (
                /* causes endless update loop */
                -- owningNode.material = previewMaterial
            )
        )
    )
)