Skip to main content

IResourceFormatLoader

Trait IResourceFormatLoader 

pub trait IResourceFormatLoader: GodotClass<Base = ResourceFormatLoader> + You_forgot_the_attribute__godot_api {
Show 19 methods // Required method fn load( &self, path: GString, original_path: GString, use_sub_threads: bool, cache_mode: i32, ) -> Variant; // Provided methods fn init(base: Base<Self::Base>) -> Self { ... } fn on_notification(&mut self, what: ObjectNotification) { ... } fn on_get(&self, property: StringName) -> Option<Variant> { ... } fn on_set(&mut self, property: StringName, value: Variant) -> bool { ... } fn on_validate_property(&self, property: &mut PropertyInfo) { ... } fn on_get_property_list(&mut self) -> Vec<PropertyInfo> { ... } fn on_property_get_revert(&self, property: StringName) -> Option<Variant> { ... } fn to_string(&self) -> GString { ... } fn get_recognized_extensions(&self) -> PackedArray<GString> { ... } fn recognize_path(&self, path: GString, type_: StringName) -> bool { ... } fn handles_type(&self, type_: StringName) -> bool { ... } fn get_resource_type(&self, path: GString) -> GString { ... } fn get_resource_script_class(&self, path: GString) -> GString { ... } fn get_resource_uid(&self, path: GString) -> i64 { ... } fn get_dependencies( &self, path: GString, add_types: bool, ) -> PackedArray<GString> { ... } fn rename_dependencies( &self, path: GString, renames: Dictionary<Variant, Variant>, ) -> Error { ... } fn exists(&self, path: GString) -> bool { ... } fn get_classes_used(&self, path: GString) -> PackedArray<GString> { ... }
}
Expand description

§Interface trait for class ResourceFormatLoader.

Functions in this trait represent constructors (init) or virtual method callbacks invoked by the engine.

Base interfaces: IRefCounted > IObject.

See also Godot docs for ResourceFormatLoader methods.

Required Methods§

fn load( &self, path: GString, original_path: GString, use_sub_threads: bool, cache_mode: i32, ) -> Variant

Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, original_path will target the source file. Returns a Resource object on success, or an [enum Error] constant in case of failure.

The cache_mode property defines whether and how the cache should be used or updated when loading the resource. See [enum CacheMode] for details.

Provided Methods§

fn init(base: Base<Self::Base>) -> Self

Godot constructor, accepting an injected base object.

base refers to the base instance of the class, which can either be stored in a Base<T> field or discarded. This method returns a fully-constructed instance, which will then be moved into a Gd<T> pointer.

If the class has a #[class(init)] attribute, this method will be auto-generated and must not be overridden.

fn on_notification(&mut self, what: ObjectNotification)

Called when the object receives a Godot notification.

The type of notification can be identified through what. The enum is designed to hold all possible NOTIFICATION_* constants that the current class can handle. However, this is not validated in Godot, so an enum variant Unknown exists to represent integers out of known constants (mistakes or future additions).

This method is named _notification in Godot, but on_notification in Rust. To send notifications, use the Object::notify method.

See also in Godot docs:

fn on_get(&self, property: StringName) -> Option<Variant>

Called whenever get() is called or Godot gets the value of a property.

Should return the given property’s value as Some(value), or None if the property should be handled normally.

See also in Godot docs:

fn on_set(&mut self, property: StringName, value: Variant) -> bool

Called whenever Godot set() is called or Godot sets the value of a property.

Should set property to the given value and return true, or return false to indicate the property should be handled normally.

See also in Godot docs:

fn on_validate_property(&self, property: &mut PropertyInfo)

Called whenever Godot retrieves value of property. Allows to customize existing properties. Every property info goes through this method, except properties added with on_get_property_list().

Exposed property here is a shared mutable reference obtained (and returned to) from Godot.

See also in the Godot docs:

fn on_get_property_list(&mut self) -> Vec<PropertyInfo>

Available on since_api=4.3 only.

Called whenever Godot get_property_list() is called, the returned vector here is appended to the existing list of properties.

This should mainly be used for advanced purposes, such as dynamically updating the property list in the editor.

See also in Godot docs:

fn on_property_get_revert(&self, property: StringName) -> Option<Variant>

Called by Godot to tell if a property has a custom revert or not.

Return None for no custom revert, and return Some(value) to specify the custom revert.

This is a combination of Godot’s Object::_property_get_revert and Object::_property_can_revert. This means that this function will usually be called twice by Godot to find the revert.

Note that this should be a pure function. That is, it should always return the same value for a property as long as self remains unchanged. Otherwise, this may lead to unexpected (safe) behavior.

fn to_string(&self) -> GString

String representation of the Godot instance.

Override this method to define how the instance is represented as a string. Used by impl Display for Gd<T>, as well as str() and print() in GDScript.

fn get_recognized_extensions(&self) -> PackedArray<GString>

Gets the list of extensions for files this loader is able to read.

fn recognize_path(&self, path: GString, type_: StringName) -> bool

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 get_recognized_extensions, and if the type is within the ones provided by get_resource_type.

fn handles_type(&self, type_: StringName) -> bool

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.

fn get_resource_type(&self, path: GString) -> GString

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.

fn get_resource_script_class(&self, path: GString) -> GString

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 "".

fn get_resource_uid(&self, path: GString) -> i64

Should return the unique ID for the resource associated with the given path. If this method is not overridden, a .uid file is generated along with the resource file, containing the unique ID.

fn get_dependencies( &self, path: GString, add_types: bool, ) -> PackedArray<GString>

Should return the dependencies for the resource at the given path. Each dependency is a string composed of one to three sections separated by ::, with trailing empty sections omitted:

  • The first section should contain the UID if the resource has one. Otherwise, it should contain the file path.

  • The second section should contain the class name of the dependency if add_types is true. Otherwise, it should be empty.

  • The third section should contain the fallback path if the resource has a UID. Otherwise, it should be empty.

func _get_dependencies(path, add_types):
	return [
		"uid://fqgvuwrkuixh::Script::res://script.gd",
		"uid://fqgvuwrkuixh::::res://script.gd",
		"res://script.gd::Script",
		"res://script.gd",
	]

Note: Custom resource types defined by scripts aren’t known by the ClassDB, so "Resource" can be used for the class name.

fn rename_dependencies( &self, path: GString, renames: Dictionary<Variant, Variant>, ) -> Error

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 Error::OK on success, or an [enum Error] constant in case of failure.

fn exists(&self, path: GString) -> bool

fn get_classes_used(&self, path: GString) -> PackedArray<GString>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§