godotengine / godotengine/godot

A type error reported when GDScript preload an scene that used this GDScript

Open
#100,285 3 comments 0 reactions 0 assignees View on GitHub
bug topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- 4.3 stable

### System information

MacOS 15, develop enviroment

### Issue description

hex_grid.gd
```gdscript
class_name HexGrid
extends Node2D
# the hex_grid.tscn used this GDScript
const HEX_GRID = preload("res://scene/hex_grid.tscn")
```

test.gd
```gdscript
class_name Module
extends Node2D
# the $HexGrid is hex_grid.tscn
@onready var hex_grid: HexGrid = $HexGrid
```

the Editor report: Trying to assign value of type 'Node2D' to a variable of type 'hex_grid.gd'
![Image](https://github.com/user-attachments/assets/29ea4b56-de65-4a08-b105-c472375eee97)

### Steps to reproduce

as reported above

### Minimal reproduction project (MRP)

NA

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported type error with the snippets from hex_grid.gd and test.gd in Godot 4.3, using the described preload and $HexGrid setup. Compare the editor's inferred Node2D type with the HexGrid annotation; done means the reported type error is understood and the relevant behavior is covered by a confirmed fix or regression test.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.