I have a bunch of keys on a piano that all share the same White Key material. I will eventually be animating values in the material to make the keys glow at different times. Now, obviously, if I animate the value, it will affect all the keys. Splitting all of the materials by clicking the + button each time for every key could understandably take a while.

enter image description here

Is there a Python script or feature that I could utilize to give each object that uses White Key its unique copy of White Key (White Key.001, White Key.002, etc.)?

  • $\begingroup$ sorry, not an answer, but sometimes, often times, brute force is faster. Your keyboard is not a full 88 keys, so I'll bet assigning a unique ID will take less time than trying to figure out how to code that. Although the code would be interesting. What about approaching it differently ? Have a parallel set of keys with the glow, but all hidden, then show each key(s) when pressed? $\endgroup$ Sep 10, 2016 at 23:40
  • $\begingroup$ @HowardPautz Brute force would be faster for the time being, but since I have a few days before I actually have to separate these things, I thought I'd look for a way to do it faster. This would also, of course, help me do it faster in the future. The multiple keys idea is interesting, but I was hoping for the light to fade in, and at that point, I'd still have to separate the materials. Thanks for replying, though! $\endgroup$
    – Shady Puck
    Sep 10, 2016 at 23:43
  • $\begingroup$ Hey YW, I'm paying attention to things like this as I'm ramping up to do some coding myself. Probably could do your way by having each key # be stored simply in an array for indexing when it's pressed, then just a simple toggle that resets the previously pressed key to white, then they pressed key set to the glow material. If you want to do more keys at once. e.g. a chord, then it gets a tad more complicated. For that, I'd use a list object. $\endgroup$ Sep 10, 2016 at 23:49
  • $\begingroup$ This post looks very much on track: blender.stackexchange.com/questions/30622/… $\endgroup$ Sep 10, 2016 at 23:51
  • $\begingroup$ Suggest using a note octave naming system. C4, A5 will all be white keys, and G#5 or Ab5 for black. $\endgroup$
    – batFINGER
    Sep 12, 2016 at 11:24

1 Answer 1


You can of course use scripts to duplicate the material around, but I have the feeling this will create a trap for you in another corner: When animating, you somehow need to animate every single material, and this I cannot imagine to be comfortable.

I suggest a slightly modified approach: Use one single material on all white keys, and create a node setup in Cycles which will hook up to an attribute of your object. In essence, you can tell the material:

hey, if the attribute of the object which I live on has a value of X, do this. Else, do this.

In other words: If X == 5 (given that X is the value you animate), and attribute Y on the object == 5 as well, glow. Otherwise, stay non-glowing. A simple Blend file showing this approach can be found here:


Animated ID value in the Blend file can be tested here:

In this Blend file, each cube has a different Object Index, starting at 0 and going up to 6. I'm using the Object Index Node to get my source value to check against:


But you could also generate a custom property on each object and read that using the Attribute Node. Whatever you decide, the next step is to generate a node tree similar to this:

Node Tree

The framed part is the IF X == Y expression. It works like this: Say we want to check if the Object Index is 3. Set the value of the top input to 3. Now, the top half of the IF expression will deduct a threshold (0.1), giving you 2.9, and then feed that into a Less Than node. So, for all Cubes with Object Index 0, 1 and 2, this will be 0 (=False =Black), as their Object Index is not less than the ID we're checking against. The bottom half works reversed, now the cubes with Index 0, 1, 2 and 3 will output white. You can preview the node outputs of less than and greater than nodes to see what I mean. The multiply nodes will multiply the results together. Since only the Cube with ID 3 received white in both cases, and only 1 * 1 = 1, it will be the only white one in the end.

The rest is 'normal' shader switching as you've done plenty of times. Now, the only value which you need to animate is the ID value in the Node Tree. You could even create an expression on it (enter #frame into the field for instance to setup a driver which links to the scene frame).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .