Topic was automatically imported from the old Question2Answer platform.
Asked By
CEDoromal
Here’s my structure:
root
Spatial
Mesh1
Mesh2
Mesh3
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:
tool
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
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
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
CEDoromal | 2019-06-29 21:43
What you’re trying to achieve with your tool script?
Dlean Jeans | 2019-06-30 03:00
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.
CEDoromal | 2019-06-30 04:02
Actually, nvm. The script somehow ran itself and worked after I ran Godot just a min ago.
CEDoromal | 2019-06-30 04:12
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.