This one would be called Enemy_Drone. Now I make a node inheriting from THAT node and overwrite the overwritten function:
print("even more different stuff")
And this node is called Enemy_Drone_Special.
Now, if I call .some_random_stuff() inside of Enemy_Drone_Special, the result will be
even more different stuff
because .some_random_stuff() will be calling Enemy_Drone’s function (which also calls Enemy’s function), but I want to call Enemy’s function directly instead of using Enemy_Drone’s so that the result is like this:
It doesn’t matter whether it’s a parent or a parent of a parent, inherited functions behave the same way and you call them using the same syntax.
That is why you are able to call functions such as look_at() on any 3D node, while the function is inherited from way up the hierarchy in the Spatial class.
I believe I have not explained the issue I have correctly and I see why. Allow me to modify the question.
however this is normally not a good idea. You are hard coding one node to use a function in another node which is not in the direct tree of the node calling it. If you delete the node with the function it will break your game and would be hard to track down the fault. Normally its better to use signals for this. A signal is something a node sends out to the whole game and then you can tell other nodes to look out for the signal and perform some code if they hear it. That way if you delete a node you wont break the whole game because it may stop a signal being sent but that will only mean the code associated with it isnt run.
I have not written my question correctly, so this wasn’t really the answer I was looking for, but thank you anyway!
Ox0zOwra | 2022-12-12 15:03
I can see your updated response but the answer doesnt change. You can either use get_node or signals. Thats how you communicate and activate functions in other nodes like this.
Gluon | 2022-12-12 15:06
I’m not trying to say that the nodes themselves are children of the particular node. It’s true that this is how you communicate between nodes in Godot, but this is not about Godot’s node trees, but more about inheritance.
I’m trying to say they’re class children, so that they inherit functions of their class parents. Or am I not getting it and you’re saying you can use get_node() for class children to use functions of their class parents like this? If this is what you’re saying, I apologize for not understanding before.
Ox0zOwra | 2022-12-12 15:17
enter code hereYou can pull functions directly from the parent with a line like this;
because the godot game engine sees this as shorthand for the get_node with the parents name in it. You are in effect using get_node with the above it is simply that the shorthand in gdnative allows you to pull from the parent. If you want to get a function from another node you need to specify which one with a line like
I read your post multiple times and the contents of the links you directed me to and I believe we may have a small misunderstanding. Imgur: The magic of the Internet
This is the part of the documentation that I am talking about. You are talking about getting parent nodes already in the scene tree. I am talking about using functions from a class that inherits from another class.
Just to make sure, I tried using get_node() on the class’ name, but it didn’t work.