When using an AnimationPlayer, you can select one animation as "autoplay on load". However, these animations won't automatically play when you are viewing the scene in the editor, only at runtime.

I have seen that you can use an AnimationTree which will make the animation play in the editor, but is there a way to make them play from the editor without adding an AnimationTree node or clicking on each AnimationPlayer and manually clicking play?

My use case is I'd like to be able to see environmental & enemy default animations when previewing my level in the editor, like these candles flickering for instance

  • award replied to this.
  • dogboydog without adding an AnimationTree node or clicking on each AnimationPlayer and manually clicking play?

    Well, that's the way Godot gives you to do it. I thought it would be interesting to find out if you could do it though, so I wrote you a hacky tool script.

    @tool
    extends Node
    
    @export var play_all: bool = false : set = run_play, get = dummy
    @export var stop_all: bool = false : set = run_stop, get = dummy
    
    func run_play(_fake_bool = null) -> void:
    	play_recursive(self)
    
    func run_stop(_fake_bool = null) -> void:
    	stop_recursive(self)
    
    func dummy() -> bool:
    	return false
    
    func play_recursive(node:Node) -> void:
    	if node is AnimationPlayer:
    		var anim:String = node.assigned_animation
    		if anim == null || anim == "" || anim == "RESET":
    			var list:PackedStringArray = node.get_animation_list()
    			var i := 0
    			while list && i < list.size():
    				anim = list[i]
    				if anim != "RESET":
    					break
    				i = i + 1
    		if anim != null && anim != "" && anim != "RESET":
    			node.play(anim)
    	for child in node.get_children():
    		play_recursive(child)
    
    func stop_recursive(node:Node) -> void:
    	if node is AnimationPlayer:
    		node.stop()
    	for child in node.get_children():
    		stop_recursive(child)

    Reload the editor after you add this script. Add it to somewhere in your hierarchy above all the AnimationPlayers and click the checkbox.

    dogboydog without adding an AnimationTree node or clicking on each AnimationPlayer and manually clicking play?

    Well, that's the way Godot gives you to do it. I thought it would be interesting to find out if you could do it though, so I wrote you a hacky tool script.

    @tool
    extends Node
    
    @export var play_all: bool = false : set = run_play, get = dummy
    @export var stop_all: bool = false : set = run_stop, get = dummy
    
    func run_play(_fake_bool = null) -> void:
    	play_recursive(self)
    
    func run_stop(_fake_bool = null) -> void:
    	stop_recursive(self)
    
    func dummy() -> bool:
    	return false
    
    func play_recursive(node:Node) -> void:
    	if node is AnimationPlayer:
    		var anim:String = node.assigned_animation
    		if anim == null || anim == "" || anim == "RESET":
    			var list:PackedStringArray = node.get_animation_list()
    			var i := 0
    			while list && i < list.size():
    				anim = list[i]
    				if anim != "RESET":
    					break
    				i = i + 1
    		if anim != null && anim != "" && anim != "RESET":
    			node.play(anim)
    	for child in node.get_children():
    		play_recursive(child)
    
    func stop_recursive(node:Node) -> void:
    	if node is AnimationPlayer:
    		node.stop()
    	for child in node.get_children():
    		stop_recursive(child)

    Reload the editor after you add this script. Add it to somewhere in your hierarchy above all the AnimationPlayers and click the checkbox.

    Nice. I was also thinking along the lines of an editor tool but was curious if there was any native way. I did try your script which worked well. I'll probably adapt something similar into the editor plugin that I have for my project so that I can call it for any scene. AnimationTree is probably the easiest way to get this to happen automatically without scripting, but I don't actually need the AnimationTree at runtime so it seems like a bit of a waste. I'll probably just go with a pair of Tools > menu items to start and stop animation players in the current scene

    Edit:

    Made this a part of my editor plugin with this C# code:

      var root=  EditorInterface.Singleton.GetEditedSceneRoot();
                    if (root == null)
                    {
                        GD.Print("No loaded scene to play animations in.");
                        return;
                    }
                    var animators = CoreUtils.FindNode2DTypesInChildren<AnimationPlayer>(root);
                    foreach (var animator in animators)
                    {
                        if (!string.IsNullOrEmpty(animator.Autoplay))
                        {
                            animator.Play(animator.Autoplay);
                        }
                    }