Scale does not seem to work

Godot Version

4.2

Question

I’m content with a hack or workaround if there is no proper solution or functionality presently. I need to be able to update the scale of a MeshInstance3D via script (because I create them at runtime/editor time via script, manually setting scale via the editor inspector is not an option).

Whenever I modify a MeshInstance via script using either of the following statements, a print statement of the “scale” property DOES properly reflect the change (print(mesh.scale)), but the change of scale (to an example/test value of float = 2.0) is NOT visually reflected in the 3D viewport:

Directly via:
global_scale(Vector3 scale)
scale_object_local(Vector3 scale)
set_disable_scale(bool disable) (both for true and false)
scale = desiredVector3
set_scale(Vector3 scale)

Indirectly via:
basis = scaledBasis
set_basis(Basis scaledBasis)
global_basis = scaledBasis
set_global_basis(Basis scaledBasis)

transform = scaledTransform
set_transform(Transform scaledTransform)
global_transform = scaledTransform
set_global_transform(Transform scaledTransform)

To add to this behavior of Scale, both position (translation) and rotation ARE correctly reflected in the 3D viewport when using their corresponding property and methods in the same block of code where the Scale code/methods are called. The problem seems specific to scale.

End of rubber ducky exercise, any suggestions are welcome.

1 Like

The culprit has been spotted, it was me. More specifically, assigning a value to the rotation property of a Node3D will also seemingly implicitly assign a default value to the scale property (Vector3.ONE, == Vector3(1, 1, 1)). internal disappointment in myself

When I was doing this with my code:

#anything that modifies scale
mesh.global_rotation.y = _tile_facing * -1 * TAU / 6

The mesh.global_rotation.y statement would overwrite any changes I had made to the scale property prior to that statement. This is because the Basis primitive in Godot marries both Rotation and Scale into a single Basis primitive, changing either of the two individual properties changes this Basis data member, and when one of the two properties is not specified, the property assignment appears to implicitly reset the other property to a default value.

The correct solution for giving BOTH properties these custom values was to manipulate a single Basis structure like so:

var basis := Basis.IDENTITY
basis = basis.rotated(Vector3.UP, desiredRotationAroundZAxis)
mesh.global_basis = basis.scaled(Vector3.ONE * desiredScale)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.