Loading resources doesn't recognise type

Godot Version

4.x (newest)

Question

I am creating a game where I use a lot of custom resources, one of which is called Page. This extends Resource. I have saved on disk each individual Page and another resource called PageList that just stores an exported array of all the pages. When I load the page_list resource it recognises it as type PageList, but then when I get the array which is typed as an Array[Page], godot does not recognise these elements as Page. I tried to chagne the _init() function for Page and made sure that all parameters have default values, but it still does not work. When I use a breakpoint and inspect the preloaded page_list Resource, the editor panel shows me this


I think that this might be the cause of the issue but I’m not sure.

Is the Page class a separate file or a subclass within PageList? It would help if you could show the code that you are having trouble with as it is really difficult to help debugging without it.

Yeah the Page class is a seperate file


This is the code that I am doing currently. The first bit is working (I renamed the argument to pagess incase that was the problem). But the second bit where is loops through the page in pages, NICE is never printed

I just changed perload() to load() and the issue is fixed. I have no idea why so if somebody does know that would be very useful.

Glad it works. From what I found on the internet is that preload does not work if there is a cyclic dependency. Say script A preloads script B and script B preloads script A. Or if the resource path is incorrect. If you are using Godot 4.4 or newer then you can use UIDs instead of the file path to load or preload resources.

May I suggest using static typing for the page_list var. That way you can get rid of the if statement checking if the var is a PageList.

    var page_list: PageList = load("res://resources/page_list.tres")
    var pages: Array[Page] = page_list.pagess

NICE will not print if the pages array is empty.
You dont need to add a semicolon at the end of each line in GDscript.