godot
godot copied to clipboard
Can't add a `CompositorEffect` to a `Compositor`
Tested versions
v4.3.dev4.official [df78c0636]
System information
Godot v4.3.dev4 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.3734) - AMD Ryzen 7 5800H with Radeon Graphics (16 Threads)
Issue description
I have been following https://github.com/godotengine/godot/pull/80214 and saw that it was recently closed. Hoping to try it out, I downloaded 4.3 dev4. However, I can't seem to add a CompositorEffect to the Compositor. I've tried using both the editor and GDScript, but neither works. Maybe there's something I'm missing on how this is supposed to work?
Using the Editor
First, in the editor, when attempting to add a new CompositorEffect to the compositor_effects array, it will only allow me to load one already created (can't create a new one).
So I tried to create one from the file system dock using "New Resource...", but CompositorEffect doesn't show up in the list of available resources.
Using GDScript
Finally, I tried to do it from GDScript. I created a new Compositor resource and added a script to it. Then I put it in my main scene. Although I was able to create a new CompositorEffect from script, I wasn't able to add it to the compositor_effects array.
extends Compositor
func _init() -> void:
print(compositor_effects)
# Trying to add a CompositorEffect via code
var compositor_effect := CompositorEffect.new()
print(compositor_effect)
# This doesn't work
compositor_effects.append(compositor_effect)
print(compositor_effects)
# This also doesn't work (even though the array currently has a null value in the first element)
compositor_effects[0] = compositor_effect
print(compositor_effects)
Steps to reproduce
- From the file system dock, create a new
Compositorresource. - In the new
Compositorresource, add an empty element to thecompositor_effectsarray. - Add the following script to the new
Compositorresource:
extends Compositor
func _init() -> void:
print(compositor_effects)
# Trying to add a CompositorEffect via code
var compositor_effect := CompositorEffect.new()
print(compositor_effect)
# This doesn't work
compositor_effects.append(compositor_effect)
print(compositor_effects)
# This also doesn't work (even though the array currently has a null value in the first element)
compositor_effects[0] = compositor_effect
print(compositor_effects)
- Create a new 3D scene.
- Add a
WorldEnvironmentnode to the scene. - In the
WorldEnvironmentnode, add theCompositorthat was created above.
Minimal reproduction project (MRP)
I can confirm that the same thing is happening to me...
Try @tool with class_name.
Demo:
https://github.com/godotengine/godot-demo-projects/pull/942
https://github.com/BastiaanOlij/RERadialSunRays
Try
@toolwithclass_name.
The problem is that I can't even create a CompositorEffect resource, let alone add a script to it. I wrote a script for a Compositor because I thought that might allow me to work around the editor and create and add a CompositorEffect from code.
I was finally able to add a CompositorEffect to the compositor_effects array by setting the entire array directly using assignment. The updated script:
extends Compositor
func _init() -> void:
print(compositor_effects)
# Trying to add a CompositorEffect via code
var compositor_effect := CompositorEffect.new()
print(compositor_effect)
# This doesn't work
compositor_effects.append(compositor_effect)
print(compositor_effects)
# This also doesn't work (even though the array currently has a null value in the first element)
compositor_effects[0] = compositor_effect
print(compositor_effects)
# This DOES seem to work (but not showing up in editor)
compositor_effects = [compositor_effect]
print(compositor_effects)
The above script prints the following out when the project is run:
[<Object#null>]
<CompositorEffect#-9223372009642130200>
[<Object#null>]
[<Object#null>]
[<CompositorEffect#-9223372009642130200>]
So for now, it seems like this might be a possible workaround through code. But I'm assuming it should still be possible to create a CompositorEffect from the editor.
Try
@toolwithclass_name.The problem is that I can't even create a
CompositorEffectresource, let alone add a script to it. I wrote a script for aCompositorbecause I thought that might allow me to work around the editor and create and add aCompositorEffectfrom code.I was finally able to add a
CompositorEffectto thecompositor_effectsarray by setting the entire array directly using assignment. The updated script:extends Compositor func _init() -> void: print(compositor_effects) # Trying to add a CompositorEffect via code var compositor_effect := CompositorEffect.new() print(compositor_effect) # This doesn't work compositor_effects.append(compositor_effect) print(compositor_effects) # This also doesn't work (even though the array currently has a null value in the first element) compositor_effects[0] = compositor_effect print(compositor_effects) # This DOES seem to work (but not showing up in editor) compositor_effects = [compositor_effect] print(compositor_effects)The above script prints the following out when the project is run:
[<Object#null>] <CompositorEffect#-9223372009642130200> [<Object#null>] [<Object#null>] [<CompositorEffect#-9223372009642130200>]So for now, it seems like this might be a possible workaround through code. But I'm assuming it should still be possible to create a
CompositorEffectfrom the editor.
You need to inherit CompositorEffect and write your own CompositorEffect, then use the CompositorEffect that you wrote.
You can refer to the demo link I gave before to see how to write a custom CompositorEffect.
You need to inherit
CompositorEffectand write your ownCompositorEffect, then use theCompositorEffectthat you wrote.
Ah, thank you. That does work.
However, seems like you should be able to create a built-in CompositorEffect from the editor without first having to extend it with your own script. Or is that just how this feature works?
You need to inherit
CompositorEffectand write your ownCompositorEffect, then use theCompositorEffectthat you wrote.Ah, thank you. That does work.
However, seems like you should be able to create a built-in
CompositorEffectfrom the editor without first having to extend it with your own script. Or is that just how this feature works?
I think it should be like this.
You must use a custom CompositorEffect, which itself has no effect, and there is currently no built-in CompositorEffect with effects.
A small note on the docs clarifying this has to be extended would help I think
You need to inherit
CompositorEffectand write your ownCompositorEffect, then use theCompositorEffectthat you wrote.Ah, thank you. That does work.
However, seems like you should be able to create a built-in
CompositorEffectfrom the editor without first having to extend it with your own script. Or is that just how this feature works?
I think it should be possible to have a button that creates a "new" CompositorEffect which is just a GDScript file that extends CompositorEffect. It would also be nice to have a similar shortcut in the "new resource" dialogue.
It is understandable why creating CompositorEffects is the way it is right now. But I think the workflow can definitely be improved.
We also need to prepare a detailed doc on creating and using CompositorEffects
However, seems like you should be able to create a built-in
CompositorEffectfrom the editor without first having to extend it with your own script. Or is that just how this feature works?
Indeed, that is how it works. The CompositorEffect class just forms the base giving you entry points where you implement the logic for an effect. In order to write that logic you'll need an implementation, hence needing to extent in GDScript or create a GDExtension for it.
I hope to get time to do some documentation for this soon, I do have a substantial demo project here: https://github.com/BastiaanOlij/RERadialSunRays And while its a long watch, I go over the demo project in detail here: https://www.youtube.com/watch?v=insa9VY0ruA
Hey guys, I would like to contribute regarding this! Is a quick glance of how to create and use a derived/extended CompositorEffect be enough for this? I'm really new to FOSS contribution, can you lemme know if we have any structure or rules to follow before getting started on contributing?
Thanks a lot in advance!
Hey guys, I would like to contribute regarding this! Is a quick glance of how to create and use a derived/extended CompositorEffect be enough for this? I'm really new to FOSS contribution, can you lemme know if we have any structure or rules to follow before getting started on contributing?
Thanks a lot in advance!
https://docs.godotengine.org/en/latest/contributing/ways_to_contribute.html
~~Is this known not to currently work with C#? I did basically a direct translation to C# from https://github.com/BastiaanOlij/RERadialSunRays and I can't get it to work. I even tried manually adding sections to the scene file to reference it, but then I get the error "Failed to set a resource of the type 'CompositorEffect' because this EditorResourcePicker only accepts 'CompositorEffect' and its derivatives".~~
EDIT: Turns out it does work. You need to use the [GlobalClass] attribute in C#. -- Thanks @raulsntos
