|
|
|
|
Reply From: |
SalgueiroAzul |
Hello! Sorry for the bump, just wanted to add a bit of code to the immensely useful comment above.
I found it a bit annoying having to type each animation name before running the script.
Especially since I want to reimport my animations often and have to change the interpolation every time.
So I made an Array with all the animation names. Then the function repeats until all the animations are done!
Should be pretty easy to use for your own projects! Just change the name of the animations.
tool # makes script run from within the editor
extends EditorScript # gives you access to editor functions
var a1 = "Fall"
var a2 = "FallLand"
var a3 = "Idle"
var a4 = "Jump"
var a5 = "PunchA1a"
var a6 = "Run2a"
var a7 = "RunStop"
var a8 = "Stance"
var name = a1 ### The selected animation
var n = 0 ### The position in the Array
var array = [a1, a2, a3, a4, a5, a6, a7, a8]
func _run(): # this is the main function
var selection = get_editor_interface().get_selection() # the selected node. In your case, select the AnimationPlayer
selection = selection.get_selected_nodes() # get the actual AnimationPlayer node
if selection.size()!=1 and not selection is AnimationPlayer: # if the wrong node is selected, do nothing
return
else:
interpolation_change(selection) # run the funstion in question
func interpolation_change(selection):
name = array[n] ### Set the selected animation to one of the array's elements
print(name)
var anim_track_1 = selection[0].get_animation(name) # get the Animation that you are interested in (change "default" to your Animation's name)
var count = anim_track_1.get_track_count() # get number of tracks (bones in your case)
#print(count)
for i in count:
anim_track_1.track_set_interpolation_type(i, 0) # change interpolation mode for every track
#print(anim_track_1.track_get_interpolation_type(i))
n += 1 ### Moves to the next element in the array
print(n)
if n < array.size(): ### If the selected animation is not the last of the array, repeat the function
interpolation_change(selection)
Hello, old tread i know, but ive made some changes to use a loop based on all the animations found on the animation player, instead of naming them all individually, also work with godot 4:
@tool # makes script run from within the editor
extends EditorScript # gives you access to editor functions
func _run(): # this is the main function
var selection = get_editor_interface().get_selection()
selection = selection.get_selected_nodes() # get the actual AnimationPlayer node
if selection.size()!=1 and not selection is AnimationPlayer: # if the wrong node is selected, do nothing
return
else:
var animlist = selection[0].get_animation_list() # finds every animation on the selected AnimationPlayer
print("animations found: "+str(animlist))
for anm in animlist: # loops between every animation and apply the fix
interpolation_change(selection,anm)
func interpolation_change(selection,strnum):
var anim_track_1 = selection[0].get_animation(strnum) # get the Animation that you are interested in (change "default" to your Animation's name)
var count = anim_track_1.get_track_count() # get number of tracks (bones in your case)
print("fixed "+strnum)
for i in count:
anim_track_1.track_set_interpolation_type(i, 0) # change interpolation mode for every track
Lady Strella | 2023-05-27 14:43
Yes! That’s incredibly useful!
Thank you so much for sharing
SalgueiroAzul | 2023-05-29 15:45