I have 2 playable characters in my scene and already have the code to switch between them.
extends Node
@onready var active = 1
func _process(delta):
if Input.is_action_just_pressed("transfer"):
if active != 2:
active += 1
else:
active = 1
How do I also switch between the cameras? I found this code but I just get the following error code: attempt to call function ‘is_current’ in base ‘null instance’ on null instance godot 4
extends Node2D
func _input(event):
if event.is_action_pressed("transfer"):
if $CameraBuddy.is_current():
$CameraBuddy.clear_current(true)
else:
$CameraShadowBuddy.clear_current(true)
Yeah I checked again and they each have their camera so I really don’t get the issue. Also should I incorporate switch camera code in the code I already have in the active manager to switch playable characters? or should I separate those codes?
I would put a breakpoint at the start of that if statement in _input and check your remote tree to make sure the cameras are in the right place. It could be it’s trying to call this before the camera exists or something.
Ok, I found the issue. I had to put: $ActiveManager/Buddy/CameraBuddy and now it’s able to find the node. however, now it’s telling me: "Invalid call. nonexistent function ‘clear_current’ in base camera2D.
func _input(event):
if event.is_action_pressed(“transfer”):
if $ActiveManager/Buddy/CameraBuddy.is_current():
$ActiveManager/ShadowBuddy/CameraShadowBuddy.make_current()
else:
$ActiveManager/Buddy/CameraBuddy.make_current