The last to lines are wrong. If you set the values inside the entitys action, you set it globally for the material, which is then used for all entitys with this material.

The rendering takes place, after all entity actions have been executed.