Godot Version 4.3
Question:
Background
Hi there! I recently started creating a game (2d platformer). I used this youtube video as a base to start as it was the easiest to follow 3D FPS State Machine Tutorial.
Given that this code is mainly for a 3D game, I had to rely on a group of other videos for varying “States” i would typically need for a 2D, but I think the code structure looks generally similar, just varying how the input would handle the movement, i.e. whether it’s a vector2 or vector3.
Issue
The engine produces 2 errors:
- The signal “TransitionSignal” is declared but never explicitly used in the class
- Invalid access to property or key ‘TransitionSignal’ on a base object of type ‘Node2D(Idle)’.
As I understand issue 1 could just be ignored using some kind of ignore warning. But I am not certain why issue 2 is popping up, given the signals look like how it was set up in the tutorial.
I have pasted the code below for reference. Thank you for reading up to this point and trying to help
State Machine Code:
extends Node
class_name StateMachine
@export var current_state : StateClass
var states: Dictionary = {}
func _ready():
for child in get_children():
if child is StateClass:
states[child.name] = child
child.TransitionSingal.connect(change_state) #<--- **this is the signal**
else:
push_warning("StateMachine contains invalid child node")
current_state.enter()
func _unhandled_input(event: InputEvent) -> void:
if current_state:
current_state.handle_input(event)
func _process(delta):
if current_state:
current_state.Update(delta)
func _physics_process(delta):
if current_state:
current_state.Physics_Update(delta)
func change_state(new_state_name : StringName) -> void:
var new_state = states.get(new_state_name)
if new_state != null:
if new_state != current_state:
current_state.exit()
new_state.enter()
current_state = new_state
else:
push_warning("State does not exist")
Idle Class Code:
extends StateClass
class_name Idle
func enter():
AP.play("Idle")
func Update(_delta):
if(Input.is_action_just_pressed("move_left") or Input.is_action_just_pressed("move_right")):
TransitionSignal.emit("Move") #<---- **This is where the error is**
func Physics_Update(_delta):
Global.player.velocity.x = 0.0
func exit():
pass