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
in Engine by (31 points)
edited by

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
by (4,005 points)
selected by

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.
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.