0 votes

Hi guys, can you point out a good tutorial on how to modify the built in nodes in godot?
In the docs i found about plug-ins, but they are good to add new custom nodes, while i would like to add a new methods to an existing one.

In particular, i would like to do an rpc call using the network ID from an array list.
It's nothing complicated by itself, but since i need to use it many time in my project i would like my base node to have it by default. Something like:

func rpc_list(list, function_name):
   for id in list:
      rpc_id(id, function_name)
Godot version 3.2.3
in Engine by (1,371 points)

1 Answer

0 votes
Best answer

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

by (4,076 points)
selected by

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

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

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.