How to run a function from a child that is its own scene

Godot Version

4.2.2

Question

I am currently trying to make a gun in Godot. The gun is a separate scene from the player scene, but is added as a child of the player scene. I currently have an input for shooting, which is meant to trigger the gun to shoot out an instance of a bullet (a separate scene). I have the bullet speed set up, as well as the code to trigger the gun. However, I cannot figure out how to run the function that shoots the bullet that is attached to the gun from within the player script. How do I run a function from another script that belongs to a child of the main scene?
There are three different scripts. One is for player movement and input, one is for making the bullet move always, and the third is for creating an instance of the bullet on the gun. I know how to create an instance of the bullet on the gun, I need help with triggering that function from the player movement and input script. Feel free to ask me any questions and extra details you need.

You can use get_node or $ to get child nodes.

$Gun.shoot()
1 Like

This is the solution. I did this solution and thought that it did not work. It turned out that the problem was that I had the function set up so that it was running incorrectly. Thank you very much.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.