Godot Version 4.2.2
Question
Hi,
I’ve got an issue with updating a variable (Last_Interacted
) from my shooting script in Godot. Here’s an overview of the problem:
- I have a shooting script attached to a RayCast3D node in my scene.
- The shooting script is responsible for detecting collisions with objects in the scene and updating a variable (
What_Hit
) with the object that was hit. - I’m trying to update another variable (
Last_Interacted
) in my Game Manager node script with the value ofWhat_Hit
when the shooting action is triggered. - However, despite the shooting script appearing to detect collisions correctly and update
What_Hit
,Last_Interacted
does not seem to be updated from the shooting script.
Here’s my shooting script:
extends RayCast3D
var What_Hit
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if is_colliding():
What_Hit = get_collider()
func _input(event):
if event.is_action_pressed("Shoot"):
var game_manager = get_node("/root/Node3D/Game Manager")
if game_manager != null:
game_manager.Last_Interacted = What_Hit
print(game_manager.Last_Interacted)
else:
print("GameManager node not found!")
Game Manager script:
extends Node
var Last_Interacted
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
print(Last_Interacted)
And my relevant scene tree:
root
Dialogic
Node3D
-Game Manager
-Player (sub-scene)
- -Collision
- -Head
- - -Camera
- - -RayCast3D (shooting script)
Have I misunderstood how scripts interact with eachother in Godot? Thanks in advance
(I first tried using signals for this, but found no way to connect it to the main scene)