Which AnimationPlayer is currently shown in bottom panel Animation?

Viewed 72

I'm trying to create my own plugin and I need to figure out which AnimationPlayer node is currently shown in the bottom Animation panel

enter image description here

and please do not suggest I use get_selection() because even if I select multiple (or none ) AnimationPlayer node(s), only one is show on the Animation Panel

so far my approach has been to try finding the node to the Animation panel using get_editor_interface() and then maybe viewing it's properties?

Edit

Based on the answer given by user @Theraot I tried this:

tool
extends EditorPlugin

func handles(object):
    print('handles=>',object);
    return true;
    
func edit(object):
    print('edit=>',object);
    

func _enter_tree():
    pass;

but using this I only get the selected nodes within the tree but even if I haven't selected any AnimationPlayer Node it still shows up in the animation panel

enter image description here

1 Answers

On your EditorPlugin implement handles to return true on any AnimationPlayer given to it, and Godot should call edit with the AnimationPlayer that is to be edited currently.

Example code:

tool
extends EditorPlugin


var edited_animation_player:AnimationPlayer


func handles(object:Object) -> bool:
    return object is AnimationPlayer
    

func edit(object:Object) -> void:
    edited_animation_player = object
    print(edited_animation_player)

I was hoping the information of which AnimationPlayer is currently being edited in the Animation panel was perhaps stored in some node for the bottom panel?

Even if get the correct node from the interface:

    var control:= Control.new()
    var animation_player_editor:Control
    add_control_to_bottom_panel(control, "puff")
    for sibling in control.get_parent().get_children():
        if (sibling as Control).get_class() == "AnimationPlayerEditor":
            animation_player_editor = sibling
    remove_control_from_bottom_panel(control)
    if animation_player_editor != null:
        print(animation_player_editor)

Which AnimationPlayer it is editing is not exposed to scripting. We can find a get_player method in the source code and a get_state method also in the source code, but we could only access them from C++, as they are not bound for scripting (source code).

In theory we should be able to get the EditorPlugin and call get_state on it, however it is not working for me:

    var animation_player_editor_plugin:EditorPlugin
    for sibling in get_parent().get_children():
        if (sibling as Node).get_class() == "AnimationPlayerEditorPlugin":
            animation_player_editor_plugin = sibling
    if animation_player_editor_plugin != null:
        print(animation_player_editor_plugin.call("get_state"))

Despite get_state being exposed on EditorPlugin, it appears to not be possible to call it.

By the way, we can see in the source code for AnimationPlayerEditorPlugin that it follows the handles and edit logic I used above.

Related