I'm making a mockup desktop for a sandbox game. I have a script, in which I defined a ObjContainer class that extends the Control class (the Container class has some behaviours that I don't want). I attached said script to the node "ObjContainer". When I check it in the Local tab of the Scene Tree, it shows that the "ObjContainer" node is of type ObjContainer as intended, shown in picture 1. When I ran the scene, I noticed that the "ObjContainer" has now suddenly turned into a Control node, shown in picture 2.*
* Edit: All nodes with custom class seem to have this behaviour. The remote tree always show native node types that I extend from. The real issue is as follows:
Calling ObjContainer-exclusive functions brings up an error that says:
Invalid call. Nonexistent function 'request_select' in base 'Control (ObjContainer)'.
Why does it do that? Every single custom-class-exclusive call worked perfectly fine previously. I even commented out the request_select() line and it ran smoothly. What's up with my ObjContainer?
The following is the script from the node calling the function:
class_name FileObject
extends MarginContainer
@onready var texture_rect:TextureRect = $VBoxContainer/Icon
@onready var label:Label = $VBoxContainer/Name
@onready var obj_container:ObjContainer = ObjContainer.new()
@onready var desktop = $/root/Desktop
@export var file_icon:Texture2D = preload("res://xeth_os/icons/collection.png")
@export var file_name:String = ""
@export var target_scene:PackedScene = null
var intended_size:Vector2 = Vector2(74, 126)
# Custom constructor.
func init(i:Texture2D, n:String, t:PackedScene) -> void:
file_icon = i
file_name = n
target_scene = t
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
texture_rect.texture = file_icon
label.text = file_name
if get_parent() is ObjContainer:
obj_container = get_parent()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func select() -> void:
modulate = Color.BLUE
label.text_overrun_behavior = TextServer.OVERRUN_NO_TRIMMING
func unselect() -> void:
modulate = Color.WHITE
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
func open_file() -> void:
var t:PackedScene = target_scene
var w:XeWindow = preload("res://xeth_os/components/window/xethos_window.tscn").instantiate()
w.init(t)
desktop.add_child(w)
func _on_gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.pressed:
obj_container.request_select(self)
if event.button_mask == 1 and event.double_click:
open_file()
if event is InputEventMouseMotion :
if event.button_mask == 1: #left mouse buton is pressed
global_position += event.relative
global_position = global_position.clamp(desktop.top_bar_offset, get_viewport_rect().size - intended_size)
And the script from the ObjContainer class:
class_name ObjContainer
extends Control
func request_selection(f:FileObject) -> void:
var l:Array[FileObject] = get_file_objects()
l.erase(f)
for i in l:
i.unselect()
f.select()
func get_file_objects() -> Array[FileObject]:
var c:Array[Node] = get_children()
var f:Array[FileObject] = []
for i in c:
if i is FileObject:
f.push_front(i as FileObject)
return f
func _on_gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
for i in get_file_objects():
i.unselect()

