# Hide Object or Collection using Keyframe

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

• Jun 5 '20 at 22:38

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

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

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

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.

• but is it possible to keyframe the visibility of a Collection? Jun 5 '20 at 5:32
• I honestly don't know. But the OP asks for a way to hide and unhide objects using keyframes. And this does that. Jun 5 '20 at 5:39
• actually it was in his question, ok thanks I was just wondering ;) Jun 5 '20 at 6:20
• 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. Jun 5 '20 at 7:02
• 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 Jun 5 '20 at 10:26

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.