+2 votes

Going through the MeshInstance and Mesh classes, I found I can retrieve the Mesh from MeshInstance.get_mesh(). Once I have a Mesh reference I can get the morph count, get morph names by index, and get and set their mode (not sure what this does), but I don't see functions for actually getting or setting morph values by index. For example, if I wanted to get the current shape amount from shape index 3, then set shape index 3 to 0.5. Does anyone know where these functions live?

Thanks,
Michael

in Engine by (46 points)

1 Answer

+1 vote
Best answer

I finally found a usage example on the old site from about a year ago. As a new user, I didn't know there was an old site. To set a morph, use the [set] method inherited from the [Object] class. Not very intuitive and poorly documented.

--Set the smile morph to 0.5
MeshInstance.set("morph/smile", 0.5)

by (46 points)

Could you comment further on this? I'm trying to figure out the morph as well and can figure out how to get it to work.

It looks like you're getting the mesh itself, then using "set(" but this does nothing for me. I can see the morph if I use the morph slider in the Inspector, but I never see it in the running game despite my settings in Inspector - so figuring out how to control this with scripts is high on my list.
Thanks :)

Here is a simple ping-pong script that you can place on your [MeshInstance] to bounce a morph value from 0-1.

extends MeshInstance

export var shapeName = "shape1"
var i = 0
var increment = true

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    if i > 1:
        increment = false

    if i < 0:
        increment = true

    if increment:
        i = i + 0.01
    else:
        i = i - 0.01

    set("morph/" + shapeName, i)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.