How to drive visibility of an object through the bone position?

Hello friends.
How do I create a bone to drive visibility of an object? I don´t understand how to link visibility of an object (on, off) driven by the position of a bone with drivers. Please help.
Thanks.

Pose mode, select the bone, open the bone properties. Then in the outliner you see the visibility toggles, right click on one for the object you want to hide -> add driver: single from target, select the bone location from the properties editor.

That creates a driver that puts the bone location as the hide value for the object. If the bone is at 0 location, hide==0, so the object is visible. If you want to flip that, you could set the expression as “1 if (var < 0.5) else 0” without quotes in the graph editor. The expression hides the object if the bone is below 0.5, otherwise it’s visible.

1 Like

Cool. Thanks for the guide. I´ll test it and post back results. Yes, the expression part of this is what had me confused. Let´s see how it goes.

How do you arm the var expression if you have 5 objects and only 1 needs to be visible when true, while all other 4 need to be false?

This is what confuses me because true is not equals 1. Integer is not boolean.

How do you write these expressions?
Thanks.

If the bone is on certain position and it shows object 1, then if I move the bone on another position then object 1 hides and object two is shown, how do you that¿?

zero equals false and non-zero does equal true. But, remember that the property being driven is Restrict Visibility, so true means it’s hidden. It’s kind of backwards to what you might expect.

Here’s a blend file with object visibility being driven by bone position. Just grab the bone and move it to see it in action. You might have to click the “reload trusted” button in the top header bar if your system, like mine, is set to restrict scripts in the downloads folder.

RestricVisibilityDrivers.blend (77.6 KB)

EDIT: Always set up a less than, greater range for the driver like I did. Never try to do an == evaluation with floating point numbers. It’s usually flaky or just doesn’t work period.

2 Likes

Besides the driver expression you can also use the driver graph curve to map position to the appropriate visibility. Use Constant interpolation on your graph keyframes.

1 Like

Thank you for those valuable observations! I was going nuts over this!

Don’t forget that you can use conditional statements in driver expressions as well, so this:

False if (var < 0.5) else True

Turns display off if the driving bone/empty/object is returning less than 0.5 in its chosen mode. This is the format for using “if” statements in Drivers, Expression Nodes in AN, etc.

Cheers, Clock.

PS. Hi Skip, long time no talk to you! how are you?

1 Like

Hey Clock,

Yeah longtime. The new forum decided to sign me up for email alerts. So I get an email about a necro reply to a two year old thread which asks me personally to re-upload an example blend. Not an issue. I actually should probably spend more time here, but my blender is rusty and I’m not 2.8 ready.

I saw your hoodlum biker chick thread. Looks good. I agree that there’s no need for protective gear in a 3D world. In 3D you might even find secret places or speed-running exploits when your head clips through the tarmac. :smiley:

Take care!

1 Like

Thank you Clockmender!! This is the part I was aiming for. I can´t believe almost 3k consulted people on Blender didn´t give this answer straight away. I guess only ex-TDs know about these expressions.
I didn´t know you could also separate statements (conditions or expressions) with a semicolon “;” to continue evaluation.
How in the world can one read that? copy and paste long lines in “VAR” section to a .txt, edit it and re-paste them?
Some stuff…

1 Like

Setting your Bender window like this helps:

Just key N for the RH menu, then drag the divide across, otherwise use the text window as you suggested. :grin:

Thanks for the kind comments and I am pleased you have a solution.

Cheers, Clock. :beers:

“eval expresion VAR;
use INT (VAR) + (some numbers);
Still 3rd line where Location has to be found;
Then use that value if it´s false;
final line to wrap up” <—

That´s what I was calling into context. I know the driver window could be widen.
Thanks! :smiley:

Sorry, didn’t immediately think of multiple lines…

Cheers, Clock. :beers:

All right. I´ve been wrecking my mind for the past 6 hours trying to break this down. My slider on the interface goes from 0m to 5 m. Which will account 0=1, 1=2, 3=4 for the variables to identify the distance. So:

If object one (standard appearence) is >1 then hide is true. (position in x =0.1, 0.2, 0.3…etc… it will be VISIBLE. This is good. Works)

If object two (hidden) is <2 then hide is true. So when my slider pass 3m, var will be greater than 2 so it becomes VISIBLE (this is good. works)

Now if I pass to distance 4m, object two remains visible because it´s greater than 2. Every other number besides 2 in positive will always make my object two visible. BUT if I add the conditional:
False if (var >=2) else (var<=3) I get a weird python scripting warning.

How do I tell blender to only register var >=2 but not as high pass 4? I need to register position (3m) as the register limit for the variable before it becomes hidden again (hide=true).

I apologize if I´m making this complicated.
Thanks for the help.

Use nested parenthesis. Like…
False if ((var > 3) and (var < 4)) else True

2 Likes

In case you reconsider using the driver curve – where you can also do this kind of complex mapping – I explain it in here:

I’m on my phone so I can’t test it, but I think a boolean-style property like bone visibility should get a value that’s either 0.0 or 1.0. That’s what I’d try first.
Edit: yeah 0.0 and 1.0 seems right, @JA12 said that in a post way above.

Thank you guys the expression: False if ((var > 3) and (var < 4)) else True
worked immediately with the desired effects. Now, Blender 2.8 crashes when I scrub back and forth the x position of the object.