How does the machine know which material is loaded?

@Julia: Same here.