how to get curent camera in tool mode

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

hi, I’m working on reflection with camera,I want run script both in editor and play

extends MeshInstance
func _process(delta):
    var currentCam = get_viewport().get_camera()

does any one know why currentCam = null in “tool mode”?
how to get curent camera in “tool mode”?

:bust_in_silhouette: Reply From: SIsilicon

Because the camera you are using to edit the scene doesn’t count.
Trust me I’d know. I created a port of someone else’s water shader to Godot 3.0!

And even if you used a camera node in the scene instead, it wouldn’t match up with your editor’s viewpoint. Making a completely broken reflection!

Yeah. So after a lil bit of digging I found this post. It’s a question from Zylann similar to yours. It may look like it didn’t get an answer, but if you keep reading the comments you’ll find out that he (sort of) answered his own question. It’s really a hack. He suggests to use the method forward_spatial_gui_input. Its two parameters are an event and get this. The editor’s camera!
Now there are obviously a couple of problems. For one the method is owned only by the EditorPlugin class. But that shouldn’t be an issue for you. And it also only gets called when you are currently editing a node from said plugin.

a coincidence , I am also making a water now,and also want to use achieve reflection with reflect camera. but there are some problem still no solve.


ywaby | 2018-05-23 07:41

Ok. Currently I am looking for an answer to this too. If I find anything, I’ll be sure to give an answer.

SIsilicon | 2018-06-03 19:01