Adding a viewport texture via tool script in editor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SIsilicon

I am collaborating with someone making a water pack for Godot. I need a way to create a proper viewport texture in the editor for reflections in editor.

var viewport =
#setup viewport and add it to node (this one)
material_override.set_shader_param('reflect_tex', viewport.get_texture())

The problem is that this seems to only work on run-time, but not in the editor!
Am I missing something? I already tried making the material local to the scene, but that didn’t seem to work.

Did you experiment with the tool keyword? (I assume you added the viewport to the scene tree given your comment?)

Zylann | 2018-06-13 12:42

Yes. The tool keyword is used in the script. :slight_smile:
And I added the viewport to the scene before getting its texture.

SIsilicon | 2018-06-13 15:18

Did you configure the viewport render mode to have a render target?

Zylann | 2018-06-13 20:21

Pretty sure I did. I mean, if I didn’t, it wouldn’t work on runtime either… Right? :-\

SIsilicon | 2018-06-14 00:41

Ah yeah, silly me.
Well, if it works ingame but tool doesn’t help, then I’m not sure what happens… tool is supposed to make your node basically run in editor, so given that you do all from code I would have expected it to work…

Zylann | 2018-06-14 01:13

Well if it helps, what happened in the editor is that it’s complaining that the viewport texture that I get has an improper node path. And that it doesn’t point to a viewport. When I check, the viewport texture has an empty node path field. I tried setting the node path manually, but that doesn’t seem to work.

SIsilicon | 2018-06-14 01:31

Maybe it has something to do with absolute node paths being different between the editor and runtime?

SIsilicon | 2018-06-14 01:33