# How to change colors during animation?

Can anybody help me with changing colors of a mesh in animation? When I change the color and set the keyframe, the last modified color of the mesh is applied on all previous keyframes. When I press i to set keyframe, which keyframe should I choose from the rolling list?

• As with most properties in Blender, material colors can be animated. Just press I with your mouse hovering over the box. See blender.stackexchange.com/questions/1284/… and blender.stackexchange.com/questions/176/… – Timaroberts Jan 11 '18 at 22:25
• Hello, I did it but obviously I am doing something wrong. I move cursor on the timeline, then I change color of the object and then I press "I". When I press "I", the rolling list pops up and there is a keyframe menu. Which keyframe should I choose? – Silvia Jan 11 '18 at 22:32
• No, press "i" on the color pick box. nearly every property can be aninated like this! – m.ardito Jan 11 '18 at 22:40

You can key frame the actual color by just hitting "i" on the color box

Starts out blue - hit "i"

Move the timeline and box and change the color and hit "i" again.

You can change color by scripting in case you don't want to resort to rendering. You need to open your text editor and change your colors like so:

def f1(hodnota, what, materialA, materialB):
if (hodnota < 0):
bpy.data.scenes['Scene'].objects[what].material_slots[materialA].material.diffuse_color[2] = value*(-1)
bpy.data.scenes['Scene'].objects[what].material_slots[materialA].material.diffuse_color[1] = 0
bpy.data.scenes['Scene'].objects[what].material_slots[materialA].material.diffuse_color[0] = 0
return value*value

bpy.app.driver_namespace['f1'] = f1


When you are happy with your function, click Run Script button in your text editor. To call the function select your driver object, go to Graph editor -> Drivers and into Expr field code something like

f1(var, 'Cylinder.002', 'Material.001', 'Material.002')


You will need to run the script each time you open your file and it is generally pain in the neck, but in case your computer is too weak to run rendered view or if you want to show what you see when developing, it is a way.

Animation

I didn't find a way to attach my blend file. Hopefully this will be enough to get you started or you will find a way to let me know how to attach it.

• Not a very good advice. Why overcomplicate everything when such a simple functionality is needed? The question is clearly about keyframe animation. It's important to know what tools are best for the job. It is definitely not Python scripting in this case. – Martin Z Nov 3 '18 at 13:00
• Welcome to BSE. Upload to blend-exchange post the link to this question where asked. Note can pass self as a reference to the object being driven. IMO drivers are a valid answer to "Change colors during animation?" On closer investigation of question, OP is having trouble with basic key-framing, however demonstrating there is another approach cannot hurt. – batFINGER Nov 3 '18 at 13:49
• It is the only way that worked for me and I thought it would be nice if I shared it in case somebody else needed it as well. – Jan Kokes Nov 4 '18 at 14:25

How to change colors during animation? with Blender Render.

Repeat steps for your next mesh/object. Thank you!