I put an FSM in my game based on the GDQuest implementation and I'm currently trying to get an attack state working, but it gets stuck. There's a function called at the end of every attack animation that's supposed to change a bool to allow the player to go back to their idle state, but for some reason, the animation doesn't play and, as such, it ends up locking the game. My code isn't much different from before when it wasn't an FSM and everything mostly worked fine there. I even tried following a tutorial I found that has a similar solution to maybe figure it out, but nothing has worked so far and I'm clueless as to why it's happening.

Attack state:

#Attack
extends State

func enter(msg := {}) -> void:
	owner.isAttacking = true;
	if msg.has("stand_light_attack"):
		owner.animState.travel("AttackLight1");

func physics_update(delta: float) -> void:
	if !owner.is_attacking:
		if owner.is_on_floor():
			state_machine.transition_to("Idle");

Player script with attackEnd function:

class_name Player
extends KinematicBody2D

#VARIABLES
export var gravity: int = 4500;
export var maxFallSpeed: int = 2750;
var isAttacking: bool = false;

var animState;
var velocity: = Vector2.ZERO;

func _ready():
	animState = $AnimationTree.get("parameters/playback");

func _physics_process(delta):
	velocity.y += gravity * delta;

func attackEnd():
	isAttacking = false;

Does the AnimationTree use animation states? Does the "attack" animation have a path that leads to the "idle" animation?

Also, there's this part: if !owner.is_attacking:. Shouldn't this part be if !owner.isAttacking:?

@Ertain said: Does the AnimationTree use animation states? Does the "attack" animation have a path that leads to the "idle" animation?

Also, there's this part: if !owner.is_attacking:. Shouldn't this part be if !owner.isAttacking:?

It should, I forgot I changed the variable name at the last second before posting, but regardless, it doesn't fix the issue.

For AnimationTree, everything is set up right as far as I know. Before the state machine, I used a single script for all the code and it worked fine there.

5 days later

Bumping this since I still haven't figured out what's going on. At first, I thought it had something to do with the message dictionary, but I got two other states that also use it and they're working fine. Also, this is the tutorial I mentioned earlier. It seemed like theirs was set up similarly, so I tried using it for testing, but no luck so far.

16 days later

What is calling AttackEnd() and the functions in the Attack State (physics_update() and enter())? Maybe I'm missing something because I have not seen the tutorial yet but it would help to see what's calling these. The bug could be that physics_update() isn't calling at all or could be a bug in state_machine.transition_to("Idle"). Maybe try printing in some of these functions to see if they're executing or not.

a year later