1
$\begingroup$

In Blender 5.0, the compositing node tree system was changed to work more like any other node group. This means there's no more "Compositing output" node, but rather a regular group output node.

The problem is, creating the group output node with Python and linking it to an image output fails to set the socket type, and we get an invalid connection.

import bpy

node_tree = bpy.data.node_groups.new(name="COMP", type="CompositorNodeTree")
bpy.context.scene.compositing_node_group = node_tree

n_img = node_tree.nodes.new("CompositorNodeImage")
n_comp = node_tree.nodes.new("NodeGroupOutput")

node_tree.links.new(n_img.outputs["Image"], n_comp.inputs[0])

Broken result

This results in the rendered image being black.

The weird thing is that if we manually remove the connection and create it again by hand in the UI, the output correctly detects the socket type:

Expected result

So how can I fix this issue and create a valid Image input on the compositor group output node?

From a similar question about Geometry nodes, the solution was to give the group output node itself an output for some reason, however running n_comp.outputs.new("NodeSocketColor", "Image") gives me RuntimeError: Error: Cannot add socket to built-in node

$\endgroup$

1 Answer 1

1
$\begingroup$

Nika helped me on chat.blender.org, crossposting here for anyone else who runs into this...

...from API perspective this is expected with new way of creating sockets. Both in and out sockets of the group have to be manually created before they can be used for linking.

Sockets are now created on tree level, not on node level

Running node_tree.interface.new_socket(name="Output", in_out='OUTPUT',socket_type='NodeSocketColor') before making the link fixes the issue:

import bpy

node_tree = bpy.data.node_groups.new(name="COMP", type="CompositorNodeTree")
bpy.context.scene.compositing_node_group = node_tree

n_img = node_tree.nodes.new("CompositorNodeImage")
n_comp = node_tree.nodes.new("NodeGroupOutput")

node_tree.interface.new_socket(name="Output", in_out='OUTPUT',socket_type='NodeSocketColor')
node_tree.links.new(n_img.outputs["Image"], n_comp.inputs[0])

It's fixed!

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.