Class ResourceFormatLoader
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Godot loads resources in the editor or in exported games using ResourceFormatLoaders. They are queried automatically via the ResourceLoader singleton, or when a resource with internal dependencies is loaded. Each file type may load as a different resource type, so multiple ResourceFormatLoaders are registered in the engine.
Extending this class allows you to define your own loader. Be sure to respect the documented return types and values. You should give it a global class name with class_name
for it to be registered. Like built-in ResourceFormatLoaders, it will be called automatically when loading resources of its handled type(s). You may also implement a ResourceFormatSaver.
Note: You can also extend EditorImportPlugin
if the resource type you need exists but Godot is unable to load its format. Choosing one way over another depends on if the format is suitable or not for the final exported game. For example, it's better to import .png
textures as .ctex
(CompressedTexture2D) first, so they can be loaded with better efficiency on the graphics card.
public class ResourceFormatLoader : RefCounted, IDisposable
- Inheritance
-
ResourceFormatLoader
- Implements
- Inherited Members
Constructors
ResourceFormatLoader()
public ResourceFormatLoader()
Methods
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
_Exists(string)
public virtual bool _Exists(string path)
Parameters
path
string
Returns
_GetClassesUsed(string)
public virtual string[] _GetClassesUsed(string path)
Parameters
path
string
Returns
- string[]
_GetDependencies(string, bool)
If implemented, gets the dependencies of a given resource. If addTypes
is true
, paths should be appended ::TypeName
, where TypeName
is the class name of the dependency.
Note: Custom resource types defined by scripts aren't known by the ClassDB, so you might just return "Resource"
for them.
public virtual string[] _GetDependencies(string path, bool addTypes)
Parameters
Returns
- string[]
_GetRecognizedExtensions()
Gets the list of extensions for files this loader is able to read.
public virtual string[] _GetRecognizedExtensions()
Returns
- string[]
_GetResourceScriptClass(string)
Returns the script class name associated with the Resource under the given path
. If the resource has no script or the script isn't a named class, it should return ""
.
public virtual string _GetResourceScriptClass(string path)
Parameters
path
string
Returns
_GetResourceType(string)
Gets the class name of the resource associated with the given path. If the loader cannot handle it, it should return ""
.
Note: Custom resource types defined by scripts aren't known by the ClassDB, so you might just return "Resource"
for them.
public virtual string _GetResourceType(string path)
Parameters
path
string
Returns
_GetResourceUid(string)
public virtual long _GetResourceUid(string path)
Parameters
path
string
Returns
_HandlesType(StringName)
Tells which resource class this loader can load.
Note: Custom resource types defined by scripts aren't known by the ClassDB, so you might just handle "Resource"
for them.
public virtual bool _HandlesType(StringName type)
Parameters
type
StringName
Returns
_Load(string, string, bool, int)
Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, originalPath
will target the source file. Returns a Resource object on success, or an Error constant in case of failure.
The cacheMode
property defines whether and how the cache should be used or updated when loading the resource. See ResourceFormatLoader.CacheMode for details.
public virtual Variant _Load(string path, string originalPath, bool useSubThreads, int cacheMode)
Parameters
Returns
_RecognizePath(string, StringName)
Tells whether or not this loader should load a resource from its resource path for a given type.
If it is not implemented, the default behavior returns whether the path's extension is within the ones provided by _GetRecognizedExtensions(), and if the type is within the ones provided by _GetResourceType(string).
public virtual bool _RecognizePath(string path, StringName type)
Parameters
path
stringtype
StringName
Returns
_RenameDependencies(string, Dictionary)
If implemented, renames dependencies within the given resource and saves it. renames
is a dictionary { String => String }
mapping old dependency paths to new paths.
Returns Ok on success, or an Error constant in case of failure.
public virtual Error _RenameDependencies(string path, Dictionary renames)
Parameters
path
stringrenames
Dictionary