+2 votes

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"?

in Engine by (34 points)

1 Answer

+1 vote
Best answer

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.

by (3,891 points)
selected by

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.


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

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.