4
$\begingroup$

I'd like to render an object only at Frame 20. The common approach seems to be set 3 keyframes at Frame 19, 20, and 21. It's not too bad, but I really wonder if I can just use the current frame number as driver input. If it is possible a single driver is enough to express "only render at Frame 20".

$\endgroup$
0

3 Answers 3

7
$\begingroup$

This is the little code you have to set on a driver on the Render icon to get the object rendered only at frame 20.

enter image description here

$\endgroup$
7
  • $\begingroup$ I assume that works because toggles are effectively boolean properties? $\endgroup$ Commented Oct 4, 2021 at 17:43
  • $\begingroup$ Yes, every on-off button is boolean, where 0.0 is off and any other value is on. $\endgroup$ Commented Oct 4, 2021 at 17:44
  • $\begingroup$ The only downside I see to this is that the object remains visible in the viewport but disappears in the render, which can confuse people debugging animation in render view, but you could apply the same driver to the viewport toggle, I suppose $\endgroup$ Commented Oct 4, 2021 at 17:48
  • $\begingroup$ Yes, it's usual to copy and paste the same driver on both. $\endgroup$ Commented Oct 4, 2021 at 17:49
  • $\begingroup$ While I was trying out my identical-answer-to-yours, I found 'Temporarily Hide in Viewport' is not keyable....I wonder if there's a getaround.. $\endgroup$
    – Robin Betts
    Commented Oct 4, 2021 at 19:29
4
$\begingroup$

There are many ways to do this. One of the easiest is to use the frame number as an input to control transparency in a shader:

Using Frame number to control Alpha

Here, the purple value field is purple because it has a driver which I've created by typing #frame into the field. This is a short cut for using the frame number. Set the frame value you want the object to appear as the second value field. If you're using this in EEVEE set the Blend Mode of the material to Alpha Clip.

You could type #frame == 25 directly into the Alpha input and it would create this driver:

driver for #frame == 25

but then it's pretty obscure what's going on.

Driver expressions are explained in the manual. You need to be aware of certain caveats but they are basically any Python expression that the driver can decode.

$\endgroup$
1
  • $\begingroup$ it's pretty hidden in your answer, and in the manual as well, but there is QUITE LITERALLY a global variable called 'frame' that gets the current frame number. $\endgroup$
    – Ron Jensen
    Commented Jun 3 at 23:26
2
$\begingroup$

you can add a custom property (i named mine "prop") and then add a driver on the camera icon of your object and insert this into your driver:

enter image description here

enter image description here

enter image description here

$\endgroup$
6
  • $\begingroup$ I didn't realize the expression in driver is literally python expression. Many thanks. $\endgroup$ Commented Oct 4, 2021 at 17:12
  • 2
    $\begingroup$ Or you could use the much simpler frame == var $\endgroup$ Commented Oct 4, 2021 at 17:23
  • $\begingroup$ @LaiYu-Hsuan Here is the Driver expression manual section $\endgroup$ Commented Oct 4, 2021 at 17:26
  • 1
    $\begingroup$ Also, the expression above contradicts the driver manual recommendation that 'Drivers should access object data via Driver Variables, rather than direct references in the Python expression, in order for dependencies to be correctly tracked.' Your driver expression can lead to unexpected behavior. $\endgroup$ Commented Oct 4, 2021 at 17:54
  • $\begingroup$ At least in Blender 3.6, bpy.context.scene.frame_current does not update during animation playback. Better to use just 'frame' which is a driver global variable (the only one). I'm adding this comment because I spent an hour after first reading this post trying to make this work. $\endgroup$
    – Ron Jensen
    Commented Jun 3 at 23:30

You must log in to answer this question.

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