How do you get viewport in Godot 4?

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

I want to do get_viewport().get_camera() in godot 4 but it tells me there is no get_viewport() any more… I should probably use get_camera3d() or some such but I need to solve the viewport problem first. Can anyone help?

it tells me there is no get_viewport() any more

Are you sure about this? It’s still a public method in Node on the master branch:

Maybe post a screenshot of the error in the editor?

Bernard Cloutier | 2021-12-17 15:11

I downloaded the latest 4.0 build and there doesn’t seem to be a problem:


Are you sure your script is on a Node and not a Resource or something else?

Bernard Cloutier | 2021-12-17 15:17

It just says ‘no function “get_viewport()” in base self’.

Macryc | 2021-12-17 15:24

What type of node is your script attached to? Please show the top of the script including the extends blahblah

Bernard Cloutier | 2021-12-17 20:26