|Topic was automatically imported from the old Question2Answer platform.
I have some doubts about using Resources in my project that I need to clear. First, I want to know if I can extend from Resource class and add my own functions, like this:
func useitem(owner, target)
The other question is, do they have some sort of inheritance? Lets say I want to have specific code for each item type:
extends BaseItem (or extends “baseitem.gd”, dont know the exact way )
func useitem(owner, target) #<-- weapons specific use function
Is this possible?
The last question is, how do I load all the resources in a directory, or how do I load a bunch of resources at once to have it in memory, an array or something? Is this optimal (lets say Im aiming to 8GB as game minimal requirements)?
Even though it is theoretically possible to extend and inherit from any native type, running it in the scene will cause an error saying
can't be instanced in object of type: 'Node'.
extends allows the script to inherit from the defined type and allows that type’s methods to be used without having to reference it first (unlike Unity if you’re familiar with
GetComponent). Accessing resources is done by referencing a node first and then getting and editing the resource that way; any changes made to it will also affect all other nodes also using that resource.
Well, last night I decided to do some tests (I dont have internet at home, so I couldnt see this answer). Yes, I could extend resource as BaseItem and the extend BaseItem as WeaponItem. The function use is called on the derived class WeaponItem if I call it in a Resource of that type. I could even store a mesh resource inside a WeaponItem Resource and use it to replace a mesh in the scene but cant find a way to instance it to create different copies in the scene. Also, couldnt attach that mesh to a BoneAttachment, I get this error: Invalid type in function ‘add_child’ in base ‘BoneAttachment’. The Object-derived class of argument 1 (ArrayMesh) is not a subclass of the expected argument class.
rogerdv | 2020-02-28 13:39