#Exporting variables for access in animation editor

4 messages · Page 1 of 1 (latest)

tepid kite
#

Hey!

I'm a new GDscript programmer, and I have a question about best practices when it comes to exposing values for the animation editor to use.

I have a variable in my player that tracks when an animation ends. To actually set this variable in the animation editor, there are two possible methods I've come across.

1. Using a Property Track

This requires I export the variable, which logically, should be private.

class_name Player
extends CharacterBody2D

@export var animation_over := false

2. Using a Call Method Track

This requires I write a new method with the sole purpose of switching the animation off, but doesn't expose the variable.

class_name Player
extends CharacterBody2D

var animation_over := false

func end_animation():
  animation_over = true

I've seen both methods used in my research. Is there a method that's more godot-like? I looked in the documentation, and it seems like there are pros and cons to both.

smoky cosmos
# tepid kite Hey! I'm a new GDscript programmer, and I have a question about best practices ...

it depends. the advantage of the property track is the fact that the value can be interpolated between the keys for a smoother animation. it can also be made so the value is continuously set each frame, even when it doesn't change, which can be useful for speciffic situations.

There is also the type Bezier which is also for interpolation between the keys, but allows more freedom how to interpolate between them.

In general you use the method track for one time triggers of something. You are also able to put multiple arguments inside the call, so in that way it's more flexible, but again that's because the values don't have to be interpolatable.

i would say for this here a property is probably better, especially since you might want to do it so the animation automatically resets the animation_over-property back to false at the start and only set it to true once it reaches a certaint point. doing that it trivial with a property track, but would require an extra function with how you're currently doing it.

#

the property track is also compatible with the reset animation, which i doubt works with methods.

#

of course, using property tracks requires you exporting the property, so if that's something you don't want, using the setter-function in a method track would probably be the only alternative.