Missing animations cache from a EditorPlugin

HI all,

on the learning path, I’m playing with turning Godot’s 2d editor into a vector graphics animator that uses the native node hierarchy and AnimationPlayer to generate a spritesheet in SVG format.

I got it to work using custom nodes in tool mode, heirs of Node2D, with everything necessary accessible and animatable from the inspector and AnimationPlayer. All the magic happens from a spritesheet function that is executed from a button in the inspector without needing to run the program. The AnimationPlayer’s callback process is set to manual and immediate, which allows me to loop through the entire animation.

I even managed to render the preview of each sprite with Inkscape. Amazed at how easy it was, I decided to go one step further and lift the whole assembly from an EditorPlugin.

The thing is that when I try to build the SVG file from a function of the plugin that calls the spritesheet function, it doesn’t find the animation cache. Also, with the editor just opened the same function works from the inspector until I call it from the plugin and I get the same error in both: No animation in cache.

I have tried to rebuild the cahe every time I export with clear_cache, which I understand is the way to rebuild it, but with no luck. I have tried all possible combinations of play, pause, seek and advance, along with await get_tree().process_frame which forced me to rebuild the process in asynchronous mode, but again no luck. I have searched queries around the subject with very few results and none of them helped me. As the cache system was rebuilt in version 4.2, there is hardly any information in the forums and the IAs are outdated. I have explored related classes and tutorials, such as SceneTree or AnimationMixer, but I can’t find an explanation.

Any idea what is going on?

Thank you in advance and sorry for the long read.

could you post the full error text and some code? I’m not sure what the animation cache is.

Hi,
first things first, thank you for your interest.
The error says nothing more than ERROR: No animaion in cache

I executed godot editor from the console with --verbose and --debug, but it says nothing more.

My node hierarchy looks as follows:

My 2d editor custom toolbar is added to the bottom:

To avoid pasting the whole SVG file generation code I will go step by step and extract only the relevant code.

In the function connected to the button press event in the 2D editor toolbar, I create an EditorFileDialog that I connect to the following function:

func _on_export_file_selected( _file_path : String ):
	if ( export_dialog != null ):
		export_dialog.queue_free() # Dialog has to be freed in order for the script to be called again.
	
	var _scene_root := EditorInterface.get_edited_scene_root()
	if not _scene_root is VAG_Spritesheet:
		push_error( "unkown error. This should not happen" )
		return
	
	var _description : String = await _scene_root.get_description()
	save_string_to_file( _description, _file_path )

Inside SVG_Spritesheet.get_description, I filter the children:

	for _sprite in get_children():
		if not _sprite is VAG_Sprite:
			continue

In each child, I check that it contains an AnimationPlayer:

		var _animation_player : AnimationPlayer = _sprite.animation_player
		if not _animation_player:
			push_error( "%s.animation_player == null" % _sprite.name )
			continue

Then I run a loop through each of the AnimationPlayer’s animations:

		var _animation_list : PackedStringArray = _animation_player.get_animation_list()
		for _animation_name in _animation_list:
			var _animation : Animation = _animation_player.get_animation( _animation_name )
			if not _animation:
				push_error( "%s animation failed" % _animation_name )
				continue
			var _step : float = _animation.step

Next is where I set up a loop that advances the animation and creates the text buffer with the SVG description frame by frame. Right now it is a hodgepodge of attempts with dozens of disabled lines of code in which I have used everything I have found in the documentation and forums but without any success. I don’t think it’s worth even pasting it here. In the version without the EditorPlugin (that works) it looks like this:

			_animation_player.set_current_animation( _animation_name )
			_animation_player.advance( 0.0 )

			for _frame in _frame_count:
				_description += _sprite.get_description( _id )
				_animation_player.advance( _step )

Thank you for your time.
Cheers!

I’m still not sure. The only places where that error appears are here and here

Try clearing the caches before playing the animation with AnimationMixer.clear_caches() and/or try using _animation_player.play() instead of assigning it manually to current_animation

Thank you for your replay.
I have already tried both suggestions, alone and combined indeed.
I have tried to call clear_cache at the beginning of the whole process and at the beggining of each animation process.
I have tried many combinations of play, pause, wait for tree.process_frame with no luck.
I have tried to use seek instead of advance too.

Holy moly, more than two weeks of circling around the subject. I had deleted the .godot folder on more than one occasion. I had rebuilt the scene countless times. I had rewritten the plugin from scratch. I had even renamed the classes in case, I don’t know, there was something out there screwing with me.
And, today, I rebuild a basic scene for the umpteenth time, because if there is something I am in this life is stubborn, and it works. I am perplexed, stunned, disoriented.
Well… I’m going to spare you a lot of swear words that I’ve let out in the solitude of my studio, but it’s just that it’s so disconcerting.

En cualquier caso, muchas gracias, Justo, por tu tiempo. :wink: