Changing conditions in AnimationTree

Godot Version

4.3

Question

Hello, all.
I’m learning how to use an AnimationTree.
I’ve created some animations and works fine.
I can move my character, walk, jump and play idle animations.

The problem is that I dont like my code:

func update_anim():
	print("estado:", estado_actual)
	match estado_actual:
		estados.idle:
			#animation_tree.set("parameters/stateMachine/current","idle")
			#animation_tree.set("parameters/Transtion/current_state","idle")
			animation_tree.set("parameters/conditions/idle",1)
			animation_tree.set("parameters/conditions/walk",0)
			animation_tree.set("parameters/conditions/jump_idle",0)
		estados.walk:
			animation_tree.set("parameters/conditions/walk",1)
			animation_tree.set("parameters/conditions/idle",0)
			animation_tree.set("parameters/conditions/jump_idle",0)
		estados.jumping:
			animation_tree.set("parameters/conditions/jump_idle",1)
			animation_tree.set("parameters/conditions/walk",0)
			animation_tree.set("parameters/conditions/idle",0)

I’m activating o deativating each animations dependenging on a var estado_actual.
Now I have only 3 animations, but I want to add a lot more, so its a bit ugly to do it this way.
How do I pass a state to my tree without having to deactivate the previous states?

Thanks in advance

1 Like

it works - don’t touch it + your code looks fine. So I wouldn’t change anything.
But this is my opinion

it’s working, I know.
But if i have like 10 animations I need to add 10 lines in each case of the match… I thought there was be a way to just put the current condition, just in one line.

I’m using AnimationTree with root = AnimationNodeStateMachine, may be with other type ?

EDIT:
I’m trying othe thing.
I’ve deleted the conditions and added expressions like this:
estado == Globals.estados.idle

I’ve created a script in the animationTree with the following code:

extends AnimationTree

var estado

func set_estado( i_estado):
	estado = i_estado

Now, I’m calling the method set_state from the player script:
animation_tree.set_estado(estado_actual)

but is not working… something is missing, i’ll check

Ooook,

Now its working this way.
But I had to change the expression from :confused:

estado == Globals.estado.idle

to

estado == idle

and created a enum without name in the animationTree script…
I think in the animationTree expressions cannot access to other scripts…

Ok, i’ve just realized that it was simplier than I thought…

Instead of passing a 0 or 1 to the method I can use a boolean expression there…
So I only need to add a line for each animation like this:

animation_tree.set(“parameters/conditions/idle”, estado_actual == estados.idle)

It’s not necessary the match statement…
newbie problems… :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.