Repository: godot
Issue: Can't connect a blend tree output programmatically
Labels: bug,needs testing,topic:animation

### Godot version

4.0.2

### System information

Mac OS Arm64

### Issue description

I am working on a 3D project that has models which I create and animate in Blender.

Describe the problem or limitation you are having in your project

I want to be able to import those models/animations easily into Godot and then create the inherited scene and then easily plug that into another scene which can configure the animations into an AnimationTree.



### Steps to reproduce

The problem I have is that it's not entirely possible to do this programmatically:

Create an AnimationTree
Add a BlendTree to the Tree
Add a BlendSpace1D to the BlendTree
Connect the BlendSpace1D to the output
It basically seems to fail on step 4. There isn't much of an API to access the Output, but you can verify that there is a node named "output" on the BlendTree. But if you try to connect(input, 0, "output") it will fail. (Also I don't know why you give it a name and an input_index).

It looks like there is an assertion actually checking to make sure you're not trying to connect the output.
https://github.com/godotengine/godot/blob/ee865051367a78bf20f50500520af13ef8f1097b/scene/animation/animation_blend_tree.cpp#LL1146C16-L1146C29

The only workaround I can find is to just pre-create a Scene that has a BlendTree already configured in the AnimationTree with a connection to output. There doesn't appear to be any API to connect an input to an output and I assume connect() is just to connect one input to another input (which in a sense is an output in that scenario).

I would really like to do anything programmatically that can be done in the GUI of Godot.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

To add functionality to be able to programmatically create an AnimationTree, add a BlendTree as the root, add a BlendSpace1D to the tree and then connect that to the output of the BlendTree

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

It seems like the connect() function can just be able to handle connecting to the output of "output". It might also be nice to have more APIs to access existing nodes on a BLendTree so better understand what is happening. I'm not sure if a new function for connecting to the output of the blend tree is necessary.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I had worked around this but I had to

Create a scene that just contains an AnimationTree
Pre-create a BlendTree as root
Add a BlendSpace1D into it
Connect that BlendSpace1D to the output of the BlendTree in the GUI
Go into my script that needed an animation tree a preload that scene
Create an instance of that scene when I configured my animationTree
Configure the AnimationTree
My problems with this is

The scene I created is not really that flexible. If I need a BlendSpace2D variant I will have to create a brand new scene
I have to do the preload -> instance dance to get it into memory, this adds more variables on my class, not sure if it makes things less performant or anything but it makes things a bit more complicated.
Is there a reason why this should be core and not an add-on in the asset library?


### Minimal reproduction project

I don't have one

This is from
https://github.com/godotengine/godot-proposals/issues/6793