#Custom resource stop being loaded when used

1 messages · Page 1 of 1 (latest)

delicate condor
#

Hey, so I have a problem that is really confusing me and I am not sure what's up. My custom resource of "CityDefinition" seem to magically stop getting that script attached to themselves? I assign them to an exported array property and if I do only that and nothing more they get the correct class. But the second I try to use the node with the exported property, they become just basic Resource objects. It's even enough if I take the node and just assign it to a variable the issue will occur, I don't even need to call on a method on it.

I've done the exact same with some other constructs like buildings and there it worked just fine?

Anyone else experienced anything like this and know what could be the cause? I couldn't find anything fitting in the github issues. Not getting any error messages in the editor or in the terminal. Running 4.2.2 on Linux if that matters.

sacred crescent
#

I've had it happen a couple of times, can't remember how i fixed it exactly.

It could be an issue with the resource it contains. Does it also stop showing properties when those variables are null?

Also, don't concern yourself too much with what the inspector shows during runtime. It is not always accurate.

delicate condor
#

I noticed the problem because of crash, the properties in the resource does not exists so script fails and errors out.
So it's not just the inspector. The CityDefinition script from what I can see is simply not loaded when used?

sacred crescent
#

Are you using preload() by chance?

delicate condor
#

For the resource type? No. But I am for other things.

sacred crescent
#

Can you show the code where the issue happens?
From the time you load it to its use.

#

Mostly so it refreshes my memory, i remember that i fixed it easily, but i can't remember how rn

delicate condor
#

Ah just stashed the files to move on (in middle of a refactor). But there's a picture on the original post with the code.

#

I am refactoring a bunch of old databases that dynamically load resources using load to instead do the management through the editor inspector so I have a suspicion there might be an order of operations here.

#

For the usage of the code, literally this would make it magically not the custom resource anymore:
var tmp := Databases.cities
Regardless of where in the code it's put

sacred crescent
#

Yep, i also had this issue with dynamic loading.

What type is "Databases.cities"?

Also, i do recommend doing an explicit casting instead of ":="

delicate condor
#

Was just doing :=since it was a test I did not expect to actually break things. But Databases is an autoload, and cities is a member variable that points to the node whose code you could see above

sacred crescent
#

And cities is Array[CityDefinition]?

delicate condor
#

No it's the node in the picture, that node has an Array[CityDefinition]

sacred crescent
#

That's an odd way to store a "database" of sorts.

Could be that since the node is kept in a variable, its @exports aren't being properly initialized. Also, if you don't need that node to enter the tree, consider turning it into a Resource or RefCounted

I've never done something like that, so i don't think i have much more in the way of possible fixes.

#

A possible trobleshooting helper would be to use ResourceSaver on those faulty Resources.
Then compare the saved one with the one you had originally with a text editor.

delicate condor
#

Having it as a node let's me reuse a bunch of stuff by composing in nodes on how the database is supposed to behave. (You can see the key cache in the examples). Variable on Databases is just quick hand for "/root/Databases/CitiesDefinitionDatabase".

I'll take a look at the ResourceSaver. After my current test. The cities have references to countries and I haven'ẗ finished them in the refactoring and wondering if it breaks because it doesn't think any references to Countries exist or something since I know gdscripts are also loaded lazily.

#

Hmmm nope that was not it, dang it

#

Yeah not looking good after I save the file with ResourceSaver, all the data is gone

#

(fixed, I had accidentally done a typo as I took the screenshot)

#

Still weird thing is, if I don't try to access the node that has the resource. it will write out the resource correctly.

#

(all I did was remove the var tmp := Databases.cities)