Hi everyone,
I'm trying to expose some of the parameters of a child node in a scene and I encounter a situation with inherited scenes.
Let's take a very simple example : The scene I want to inherit (SceneParente) has two Node nodes The child node (Dummy) has a _dummy_var parameter that I would like to see exposed when I instantiate the scene
The script attached to the Dummy node defines a Setter and a Getter for the dummy_var variable and prints in the console the passage in the init and _ready function.
tool
extends Node
var _dummy_var : String = "rien" setget set_dummy_var, get_dummy_var
func _init() -> void:
print("_init Dummy (" + str(get_instance_id()) + ")")
func _ready() -> void:
print("_ready Dummy (" + str(get_instance_id()) + ")")
func set_dummy_var(value : String) -> void:
_dummy_var = value
func get_dummy_var() -> String:
return _dummy_var
The script attached to the SceneParente root node exposes the variable dummy_var of the Dummy node using the get_property_list() method and, as for the script of the Dummy node, prints the passage in different methods in the console.
tool
extends Node
var _dummy_child : Node
func _get_property_list() -> Array:
print("_get_property_list SceneParente")
var properties := Array()
properties.append({
name = "dummy_var",
type = TYPE_STRING,
usage = PROPERTY_USAGE_DEFAULT
})
return properties
func _set(property: String, value) -> bool:
match property:
"dummy_var" :
print("_set SceneParente dummy_var")
_dummy_child.set_dummy_var(value)
return true
_ :
return false
func _get(property: String):
match property:
"dummy_var" :
print("_get SceneParente dummy_var")
return _dummy_child.get_dummy_var()
_ :
return null
func _init() -> void:
print("_init SceneParente (" + str(get_instance_id()) + ")")
func _enter_tree() -> void:
print("_enter_tree SceneParente (" + str(get_instance_id()) + ")")
_dummy_child = $Dummy
func _ready() -> void:
print("_ready SceneParente (" + str(get_instance_id()) + ")")
Everything works perfectly, _dummy_var is correctly exposed in the inspector and the order of execution of the methods gives this in the output :
_init SceneParente (31429)
_init Dummy (31430)
_enter_tree SceneParente (31429)
_ready Dummy (31430)
_ready SceneParente (31429)
_get_property_list SceneParente
_get SceneParente dummy_var
get_property_list() is called after enter_tree, dummy_child is correctly defined. But if I create a new scene inherited from SceneParente, let's call it the SceneFille, and I attach a script inherited from SceneParente's script (containing only the output of the passages in the different methods), the order of passage changes. enter_tree is called after get_property_list(), dummy_child is not defined and Godot raises an error :
_init SceneParent (60503)
_init Dummy (60504)
_get_property_list SceneParent
_get SceneParent dummy_var
res://SceneParente.gd:43 - Invalid call. Nonexistent function 'get_dummy_var' in base 'Nil'.
_init SceneParent (60503)
_init SceneFille (60503)
_enter_tree SceneParent (60503)
_enter_tree SceneFille (60503)
_ready Dummy (60504)
_ready SceneParent (60503)
_ready SceneFille (60503)
_get_property_list SceneParent
_get SceneParent dummy_var
Did I miss something? Thanks for your help!