This would likely be easier using tagging both objects and checking that those match.
Better still would be to give the actors an ID and using an interface to check if they match.
Materials might be a bad choice because, if you ever want to use a dynamic material instance, to say light up the boxes or give some sort of status feedback, then those dynamic materials will never match.