4
$\begingroup$

I have seen tutorials on the older Blender version to hide and unhide an object using keyframes. I haven't been successful in 2.8. I thought you could use collections to control this, but no luck.

I basically want to control the visibility of an object and various parts of the timeline. What's the trick in 2.83. Thanks

$\endgroup$
2

4 Answers 4

7
$\begingroup$

Hiding a collection

None of the hide properties of the collection are animatable. That is cannot drive or keyframe them.

Can however use a frame change handler to set.

Here is a trivial example that sets the visibility of all immediate children of the scene collection to un hide when frame is in on list, and hide when frame in off list.

import bpy

on = [1, 44, 66]
off = [10, 55, 77]


def frame_change(self):
    frame = int(self.frame_current)
    for c in self.collection.children:    
        if frame in on:
            c.hide_render = c.hide_viewport = False
        elif frame in off:
            c.hide_render = c.hide_viewport = True

#bpy.app.handlers.frame_change_pre.clear()       
bpy.app.handlers.frame_change_pre.append(frame_change)

Using a keyframed prop

enter image description here

Alternatively can give the scene a custom property. Make it an integer by giving it a value and default that is an integer.

In the graph editor make the extrapolation constant.

Now we have a keyframable switch to turn on off collection switches.

import bpy

def frame_change(self):
    frame = int(self.frame_current)
    print(frame, self["prop"])
    for c in self.collection.children: 
        c.hide_viewport = c.hide_render = self["prop"]   


#bpy.app.handlers.frame_change_pre.clear()       
bpy.app.handlers.frame_change_pre.append(frame_change) 

Uncommenting (removing hash #) from second last line cleans the previous handlers

See also

How can I exclude a collection from rendering with Python?

How to get all collections of the current scene?

disable all collections with python in blender 2.8

Sorting Collections Alphabetically in the Outliner

$\endgroup$
5
$\begingroup$

Many properties in the Properties Panel are animatable, including viewport visibility. Click on the Object Tab (not the Object Data Tab), then look Under the Visibility Section for a property called Show in Viewports and Show in Renders. The small dot to the right of these properties can be clicked to set a keyframe.

enter image description here

$\endgroup$
5
  • 2
    $\begingroup$ but is it possible to keyframe the visibility of a Collection? $\endgroup$
    – moonboots
    Commented Jun 5, 2020 at 5:32
  • $\begingroup$ I honestly don't know. But the OP asks for a way to hide and unhide objects using keyframes. And this does that. $\endgroup$
    – R-800
    Commented Jun 5, 2020 at 5:39
  • 1
    $\begingroup$ actually it was in his question, ok thanks I was just wondering ;) $\endgroup$
    – moonboots
    Commented Jun 5, 2020 at 6:20
  • $\begingroup$ His question was how to keyframe visibility. In the first paragraph, he happens to mention that one of the things he thought to try in order to get visibility keyframed was to use collections, presumably because they have a visibility toggle. According to him, this possibility didn't pan out. In the second paragraph, he states very clearly what he wants. $\endgroup$
    – R-800
    Commented Jun 5, 2020 at 7:02
  • 1
    $\begingroup$ I meant it seemed to be in the title, anyway it would make sense to keyframe collection visibility, I don't know why it's not the case $\endgroup$
    – moonboots
    Commented Jun 5, 2020 at 10:26
1
$\begingroup$

By using an instance of the collection, you can keyframe its visibility/rendering. I found it in this tutorial: https://www.youtube.com/watch?v=bDF21pjxXAY

It's a bit tedious to properly position the instanced collection but afterwards it works like a charm.

$\endgroup$
-1
$\begingroup$

Use a keyframe on scale - set X, Y and Z scale to 1 for object to be visible and scale to 0 for invisible. Probably a good idea to Ctrl + A and apply scale first. This only needs to be done on the parent object and all children will follow the parent. You might have to add an extra keyframe to make the object disappear from one frame to the next, otherwise the object will appear to shrink or grow.

$\endgroup$

You must log in to answer this question.

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