Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Qushy |
Hello I have a script on my camera and a target variable in that script which I’ve exported. I am trying to access the variable from the player script and it doesn’t work. Here’s the code in the player script:
var camera
var hextor
hextor = get_tree().get_root().get_node("Stage").find_node("Hextor")
camera = get_tree().get_root().get_node("Stage").find_node("Camera")
camera.target = hextor
I get an invalid index error. What am I doing wrong?
The exact error:
Invalid set index 'target' (on base: 'Camera2D') with value of type 'KinematicBody2D (player.gd)'.
How does the script on your Camera2D look like? Do you only have one Camera2D-node or multiple ones? Are you sure the script is attached and the variable is named target
? The error tells you that you’re accessing an index of your Camera2D-node which doesn’t exist - either because the script does not exist or the variable is named differently. The code you provided looks correct - I cannot reproduce the issue!
njamster | 2020-03-25 23:28