godot
godot copied to clipboard
Editor cannot cast constant subresource when accessed by through variable index
Tested versions
Reproducible in 4.4-beta1, 4.4-rc1
System information
Godot v4.4.rc1 - Windows 11 (build 22631) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 32.0.15.6094) - AMD Ryzen 7 5800X 8-Core Processor (16 threads)
Issue description
Attempting to assign a variable typed to resource class creates error message if it was accessed from an array or dictionary of another constant resource with a variable used as an index. Loading it, instead of preloading, does not have this issue.
Steps to reproduce
Create a custom resourcesuch as:
class_name MyResource
extends Resource
@export var sub_resource_arr: Array[MySubResource]
@export var sub_resource_dict: Dictionary[int, MySubResource]
And another with:
class_name MySubResource
extends Resource
Create a new resource of that type, then attempt to assign a variable like so:
class_name MyClass
extends Node
const resource: MyResource = preload("res://my_resource.tres")
func _ready():
var index: int = 0
var sub_resource: MySubResource
var loaded_resource: MyResource = load("res://my_resource.tres")
sub_resource = loaded_resource.sub_resource_arr[index]
sub_resource = resource.sub_resource_arr[index]
sub_resource = resource.sub_resource_dict[index]
The editor throws an error for the last two lines in _ready().
Line 11:Value of type "res://my_sub_resource.gd" cannot be assigned to a variable of type "MySubResource".
Line 12:Value of type "res://my_sub_resource.gd" cannot be assigned to a variable of type "MySubResource".
Minimal reproduction project (MRP)
N/A