Changing enemy color on perception


I am trying to create an instance were when the enemy sees the player his mesh changes color or material changes. I had this working before using a dynamic material instance in my characters blueprint and then casting to my player type to get the variable. However, now it stopped working and is giving me a failed to cast error. Anyone have a solution on how to fix this? Also, how can I check to see the player is no longer in the enemy sight?

Thank you