You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ERR_PRINT("Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message());
return Ref<Resource>();
}
if (r_error) {
*r_error = OK;
}
return json;
}
This method can correctly load and parse a json file, but when it gets returned, the Ref<Resource> becomes null, because it can not be converted into a Resource. This is because of this:
JSON is derived from RefCounted, but not from Resource. This seems to be somewhat indentional, but why is there a specific ResourceFormatLoader if it will never be able to load it?
I tried to change the base class of JSON to Resource and the ResourceFormatLoader can load it, but just changing the base class will probably not be enough and lead to other bugs. I just wanted to open this issue to point out that something needs to be done to fix this.
The problem (as noticed by @PucklaMotzer09 ) is that currently the inheritance tree looks like this:
Object
└── RefCounted
├── Resource
└── JSON
This means that JSON cannot be loaded using ResourceLoader, because it's not actually a Resource.
One solution would be to make JSON a Resource, as initially suggested by @PucklaMotzer09 . Possibly we would have to move several types around, like FileAccess, which seems to be similar (also a file, but without a specific format).
Another solution is to make the ResourceLoader.load method return Ref<RefCounted>, which also seems like a huge change. Probably ResourceLoader would have to be renamed to RefCountedLoader :)
For now I'd like to submit a PR that makes JSON a Resource, and if we choose a different direction, please let me know and I'll amend it ;)
Godot version
4.0 beta3
System information
Garuda Linux
Issue description
There is a dedicated
ResourceFormatLoader
for JSON, but this loader can not load JSON files because the JSON class is not aResource
:godot/core/io/json.cpp
Lines 582 to 609 in 61051a4
This method can correctly load and parse a json file, but when it gets returned, the
Ref<Resource>
becomes null, because it can not be converted into aResource
. This is because of this:godot/core/io/json.h
Lines 39 to 40 in 61051a4
JSON
is derived fromRefCounted
, but not fromResource
. This seems to be somewhat indentional, but why is there a specificResourceFormatLoader
if it will never be able to load it?I tried to change the base class of
JSON
toResource
and theResourceFormatLoader
can load it, but just changing the base class will probably not be enough and lead to other bugs. I just wanted to open this issue to point out that something needs to be done to fix this.Related: #66820
Steps to reproduce
ResourceLoader.load
.Resource
is null, but the error isOK
.Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: