0
$\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
$\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

| improve this answer | |
$\endgroup$
1
$\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

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ but is it possible to keyframe the visibility of a Collection? $\endgroup$ – moonboots Jun 5 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 Jun 5 at 5:39
  • 1
    $\begingroup$ actually it was in his question, ok thanks I was just wondering ;) $\endgroup$ – moonboots Jun 5 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 Jun 5 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 Jun 5 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.