0 votes

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 = Viewport.new()
#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.

asked Jun 13 in Engine by SIsilicon (1,173 points)

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

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

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

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

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...

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.

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.