Amending a lightswitch field value inside a matrix, from a plugin? I have a plugin which is used to send a notification email when certain events happen.

I need to watch the contents of a Matrix field attached to a User, and when a Lightswitch field inside the Matrix is 'on', flip another Lightswitch field on the same matrix block. Here's the simplified code I have so far:

craft()-&gt;on('users.onBeforeSaveUser', function(Event $event) {
    foreach ($user-&gt;getContent()-&gt;myMatrixField as $matrixBlock) {
        if($matrixBlock-&gt;firstLightswitch){
            $matrixBlock-&gt;secondLightswitch = '1';
        }
    }
}


I am getting the following error though:


  Property “Craft\MatrixBlockModel.secondLightswitch” is not defined


It's very definitely defined. I presume I'm trying to set the field incorrectly, but can't find out how.
You have to do: 

$matrixBlock-&gt;getContent()-&gt;setAttribute('secondLightswitch', '1');


You can only get attributes via magic methods but you can't set them