Trying to run a @tool script in the editor crashes when trying to access non-native class variables. Did and does work in 4.5, any breaking changed I should be aware of?
Basically I am trying to create some tiles via the in-editor script, see code below. I CAN set the owner of the class, I assume because it extends Node2D which nativly has owner. I CAN NOT however, access “pos” which is a variable of type Vector2i and is part of my custom MTile class.
Error Code:
ERROR: res://Level/map_helper.gd:27 - Invalid assignment of property or key ‘pos’ with value of type ‘Vector2i’ on a base object of type ‘Node2D (MTile)’.
func _run():
var level = (EditorInterface.get_edited_scene_root() as Level)
var tileAnchor : Node2D #= .... just grabbing a node.
for i in level.mapSize.x:
for j in level.mapSize.y:
var newNode : MTile= protoTile.instantiate()
tileAnchor.add_child(newNode)
newNode.owner = level
newNode.pos = Vector2i(i, j)
I recommend logging this as a bug in the Godot Project. Until a new version is actually released, there is limited testing done by the community. So a number of bugs are found in the first week. This is why there are .1 releases released a week or two after the initial release.
Is this the actual code?
tileAnchor is never created and that should be erroring.
I guess it actually looks something like var tileAnchor : Node2D = $MyNode
If you are going to post a bug report they are going to want a minimal reproduction project.
Please link your bug report here if you file it.
I could only replicate this error by deliberately misspelling .pos. But I also haven’t tested on 4.6 yet. Tomorrow I will test it on that version.
I tried this on 4.6 (v4.6.beta3.official) and could not reproduce the problem.
Here is what I tried:
#Class MTile
@tool
class_name MTile extends Node2D
var pos:Vector2i:
set(value):
pos = value
prints(value, "MTile" )
and
# test class
@tool
extends Node2D
@export var moo:Vector2i:
set(value):
moo = value
var protoTile:PackedScene = load("res://m_tile.tscn")
var newNode : MTile= protoTile.instantiate()
newNode.pos = Vector2i(12, 12)
prints(newNode.pos, "Test")
Everything prints as expected and no errors.
Is there more to the MTile class or the scene structure that might be impacting this?