Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | moniker |
I’m relatively new to Godot so I’m hoping this is just a simple mistake. I’m using version 3.3 (Linux 64 build). I want a series of nodes which each maintain a list of ‘related’ nodes. To make this easier I have written an editor ‘tool’ script, which is attached to each node, and can create new related nodes when I click a ‘button’ (exported bool var). This script just adds a node to the scene/tree and performs push_back() on an array of related nodes for the node doing the adding.
The problem is that after adding a few nodes with the tool, Godot editor will crash when I try to save. I assume I’m trying to access something in a way which is incorrect. In particular, if the array of related nodes isn’t exported (viewable in the editor), it doesn’t crash. Or if I don’t add the newly instanced node to an array it doesn’t crash. It also doesn’t crash if the array isn’t ‘exported’, so I think it could be to do with how exported arrays are handled by the engine?
Minimal code example of the tool here:
tool
extends Sprite
export var relatedList = [] #No crash if the array isn't exposed
export (bool) var createNewTool = false setget create_new #editor 'button' to create new instance
var sceneResource = load("res://MySprite.tscn")
func create_new(value):
if Engine.is_editor_hint():
#create new instance and add to scene/tree
var newSprite = sceneResource.instance()
get_parent().add_child(newSprite)
newSprite.set_owner(get_tree().get_edited_scene_root())
#update list of related nodes
relatedList.push_back(newSprite)
newSprite.relatedList.push_back(self)
#update exported array values
property_list_changed_notify()
newSprite.property_list_changed_notify()
To recreate: Create a new project. Add Node2d. Add a Sprite to the Node2d. Attach the above script and save sprite as “MySprite.tscn”. Click the ‘createNewTool’ checkbox in the editor to create a new instance (this works fine). Now click the newly created MySprite and click the ‘createNewTool’ checkbox on that. Try to save (ctrl+s) and editor will crash.
Editor log doesn’t provide anything useful as far as I can tell:
Godot Engine v3.3.stable.official - https://godotengine.org OpenGL ES
3.0 Renderer: GeForce GTX 1060/PCIe/SSE2 OpenGL ES Batching: ON
WARNING: Font oversampling only works with the stretch modes “Keep Width”, “Keep Height” and “Expand”, not “Ignore”. To remove this
warning, disable Rendering > Quality > Dynamic Fonts > Use
Oversampling in the Project Settings. At:
scene/main/scene_tree.cpp:1161:_update_root_rect() - Font oversampling
only works with the stretch modes “Keep Width”, “Keep Height” and
“Expand”, not “Ignore”. To remove this warning, disable Rendering >
Quality > Dynamic Fonts > Use Oversampling in the Project Settings.
Any help greatly appreciated!