|
|
|
 |
Reply From: |
Wakatta |
Pretty sure that’s the purpose of the extends
keyword as you can create a custom class using Reference
, Object
, Node
as the base then have every other node in your game extend from that.
Example Base
class_name Base extends Node
var foo_list = []
func rpc_list(list, function_name):
for id in list:
rpc_id(id, function_name)
Example other
class_name Ball extends Base
func roll():
do_roll()
Example extra
class_name Glove extends Ball
func _ready():
rpc_list(foo_list, roll)
Other than that to do exactly what you want would require building your own version of Godot from the source
yeah, extends and classes are very similar to plugins, they are good for creating custom objects, but i need to modify an existing one, othervise i need to create a custom class for every godot node type (eg: static body, rigid body, node2d, control, etc), while if i could add the new method to Node
, every other node would inherit automatically
i think i have to learn more about the source then, thanks for pointing it out
Andrea | 2021-03-06 21:28
Yeah that’s a downside to this approach however you only need to do it for top level classes in your scene tree.
Example
[+] node_that_extends_base_class
[-] every other nodes who's functionality i need
A simpler less invasive approach to achieve what you want though would be to have a singleton with all the functions you’ll need to use that accepts a node as one of its parameters
For each node that can access those methods use set/get_meta
to set your lists
Wakatta | 2021-03-06 21:54
that’s it
i never used autoload, this solution is a good compromise between ease of use (accessible to every node) and ease of implementation
thank you!
Andrea | 2021-03-07 13:09