0 votes

Here's my structure:




How do I access these mesh's properties (positions, to be specific) using a script in editor?

I tried using a tool script attached to the Spacial node but every time I run it in editor, I get this error: modules/gdscript/gdscript.cpp:557 - Condition ' !p_keep_state && has_instances ' is true. returned: ERR_ALREADY_IN_USE

However, when I play the scene, I get this error instead: Invalid get index 'position' (on base: 'MeshInstance').

I don't know how you set and get the values of a node's properties so please bear with me.

This is what I wrote:

extends Node
var x = 0
var z = 0
func _ready():
    for childNode in get_node(".").get_children():
        childNode.position.x = x
        childNode.position.z = z
asked Jun 29, 2019 in Engine by CEDoromal (30 points)
edited Jun 29, 2019 by volzhs

1 Answer

+1 vote
Best answer

MeshInstance inherits from Spatial which got no position property.
The 3D version of position is translation, so it's:

childNode.translation.x = x

And instead of global_position:

childNode.global_transform.origin.x = x
answered Jun 29, 2019 by Dlean Jeans (3,873 points)
selected Jun 30, 2019 by CEDoromal

Any idea on how I can run this in the editor? Because it still keeps saying this: modules/gdscript/gdscript.cpp:557 - Condition ' !p_keep_state && has_instances ' is true. returned: ERR_ALREADY_IN_USE

What you're trying to achieve with your tool script?

I'm trying to easily spread out all MeshInstances in the editor using a script instead of manually changing their positions one by one. I might also try experimenting with the shaders and some other properties once I fully understand it.

Actually, nvm. The script somehow ran itself and worked after I ran Godot just a min ago.

Ohh.. I get it. I just realized why I'm getting the ERR_ALREADY-IN-USE.
Apparently you just have to reopen the scene to make it work.

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.