How to change Blend Shape/Blend Key value with slider?

Godot Version

4.3

Question

I am trying to make a character creator, and want to include a slider that would change the size or shape of a feature with a blend shape/key. I already know how blend keys in Blender work, but I’m still very new to game dev and Godot, and have no idea how to implement this. I imagine it’s possible.

So far I’ve figured out how to import a model with blend shapes, and how to signal the value_changed/_on_h_slider_value_changed to the mesh’s script. Don’t know where to go from there… Any help at all will be very much appreciated :3

MeshInstance3D has a set_blend_shape_value function, so long as you know the blend shape index and it’s value bounds you can directly connect the value changed to the set blend shape function

func _on_h_slider_value_changed(value: float) -> void:
    $MyCharacterMesh.set_blend_shape_value(0, value)
1 Like

Thank you for responding! I think I’m still missing something, because interacting with the slider only changes the mesh once by whatever the value is. No more increasing or decreasing after that, it’s acting like a button that only works once.

I think I should also have mentioned that the mesh I want to change the blend shapes of has multiple blend shapes. So maybe I need a way to define what blend shape I’m trying to change with each slider.

Do any messages appear in your output or debugging panel?

Yes, the first argument is the index. in my example I used 0, you will need to fill in a value for each slider, you would use multiple functions or bind the index during the connection.

1 Like

No errors in output or debugging when 0 is used, except for The parameter "value" is never used in the function "_on_h_slider_value_changed()". If this is intended, prefix it with an underscore: "_value". Then none at all when I do as the error says.

When I use “blend_shapes/Width” in place of 0, I get the error:
Invalid type in function set_blend_shape_value in base MeshInstance3D (cube_2.gd). Cannot convert argument 1 from String to int.

Could you share your code? This sounds like it sets the blend shape to 0, and doesn’t use value, which is different from my sample

What do you mean by “use ‘blend_shapes/Width’”?

That’s the property of the specific blend shape I’m trying to change the value of. Should have specified that.

Here’s my code. I fear I may be too new to programming to do what I’m trying to do…

extends MeshInstance3D

func _on_h_slider_value_changed(value: float) -> void:
	%Cube2.set_blend_shape_value("blend_shapes/Width", 0.1)

Thanks for sharing, the first parameter must be a number, it’s the index of which blend shape to edit starting at 0.

The second parameter is the value to set the shape to. You want this to be value for it work based on the slider’s value.

extends MeshInstance3D

func _on_h_slider_value_changed(value: float) -> void:
    %Cube2.set_blend_shape_value(0, value)
1 Like

AAAH It works! Finally! It took me way too long to process what you were trying to tell me, but I get it now.

Thank you for the help! :3